-1

I'm trying to write a login script for phones that takes the URL, user, and password from a CSV file and then inputs it to my function. I would love for it to loop so once it completes the first login it uses the next row in the CSV file to update the variables until it has reached the end of the CSV file.

My CSV table file looks like this:

url,user,pass
10.10.10.1,bob,notclean
10.10.10.2,sara,weeee
10.10.10.3,jim,elmo

This is my code thus far. If I replace those variables in the function with the details from CSV file it works.

import selenium
import time
from pandas import DataFrame, read_csv
import pandas as pd
import numpy as np

#open csv file and read table
file = r'table.csv'
df = pd.read_csv(file)


#login function
def login_user(site, login, upass):
    driver = webdriver.Chrome(executable_path="chromedriver.exe")
    driver.get(site)
    time.sleep(6)
    driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/form/div/div[1]/label/div/div[2]/div/input').send_keys(login)
    driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/form/div/div[2]/label/div/div[2]/div/input').send_keys(upass)
    driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/form/div/div[3]/div/div').click()

How do I correlate url to site, user to login, and upass to pass in the excel document and then loop the function to retry my logins until I've reached the end of the CSV file?

John Doe
  • 19
  • 5
  • I am sorry I don't understand your question properly, can you explain a bit more... If I understand correctly, you are trying to login with one row of credentials into the URL written in that row, then you are login into the next URL with a different row of credentials? – Sabito stands with Ukraine Oct 30 '20 at 03:43
  • Each row contains a url for a phone and the username/pass for the user. My goal is is use this script to automatically sign phones in with default credentials. However, those credentials change from phone to phone. So I need to read the row from the csv file, store the values from that row into 3 variables, and then run my function with those variables then repeat the process again with the next row. – John Doe Oct 30 '20 at 03:51
  • Does this answer your question? [How to iterate over rows in a DataFrame in Pandas](https://stackoverflow.com/questions/16476924/how-to-iterate-over-rows-in-a-dataframe-in-pandas) – Sabito stands with Ukraine Oct 30 '20 at 04:01
  • Not really. I don’t understand how I would take The data in the csv and translate into a variable. – John Doe Oct 30 '20 at 12:03

1 Answers1

0

I wasn’t able to pull the data from my csv file, but realized I can just run the function over and over.

Login_user(google.com, me, password1) Login_user(stackoverflow.com, hi, 2u) Etc

I can just use notepad++ and create the script easily.

John Doe
  • 19
  • 5