0

I have a function that needs two arguments: user and password, both of them are strings. My problem is that I want to get the arguments from an Excel file (user and password) How can I do it? :(

enter image description here

The function looks like this (I'm using Selenium with Chrome):

def login(user,passwd):
    createDir()
    driver.get('https://www.fasab2b.com/FasaCL/BBRe-commerce/access/login.do')
    driver.maximize_window()
    txtId = driver.find_element_by_id("logid")
    passw = driver.find_element_by_id("password")
    txtId.send_keys(user)
    passw.send_keys(passwd)
    passw.send_keys(Keys.RETURN)

I want to execute the function with something like this:

for user,password in excelFile:
    login(user,password)
    print("login made with: " + user + password)

Thankful for any help

  • 1
    Have you looked into libraries for Python & Excel? http://www.python-excel.org/ – Josh Clark Apr 14 '20 at 17:35
  • 1
    Use Pandas .. you'll enjoy it. – Minions Apr 14 '20 at 17:38
  • Can you clarify what exactly the issue is? Have you tried anything, done any research? Please see [ask], [help/on-topic]. – AMC Apr 14 '20 at 19:02
  • Does this answer your question? [Read Excel File in Python](https://stackoverflow.com/questions/22169325/read-excel-file-in-python) – AMC Apr 14 '20 at 19:03

1 Answers1

0

I'd suggest openpyxl.

This is how to access a worksheet from an existing Excel file.

import openpyxl

wb = openpyxl.load_workbook('data/test.xlsx')
ws = wb.worksheets[0]

So it is very easy to create, for example, a function returning a list of tuples from all the rows (from the second, skipping the header, to the last one) and from specific columns (3 and 4, again in your example) of a given Excel file

def excelLogins(path):
    wb = openpyxl.load_workbook(path)
    ws = wb.worksheets[0]
    ret = []
    for i in range(2,ws.max_row + 1):
        ret.append((ws.cell(i,3).value,str(ws.cell(i,4).value)))
    return ret

Since your passwords would be interpreted as numbers from Excel, you might also want to convert them to strings, as already done above. Eventually, you can print the results as you prefer

for user,password in excelLogins('data/test.xlsx'):
    print("login made with: " + user + ':' + password)