0

I'm trying to create a script that :

  • Open Browser -> Go to a website (logging page) -> Auto Logging (filling up email and password details from csv file ) -> Close Tab -> Re open again the website -> Re Auto logging but with the second account (filling up details from csv file SECOND ROW ) .

... Re do the same tasks 50 times (From account 1 to 50 for example)

import pandas as pd
from selenium import webdriver

//Open Browser and go to facebook logging page
browser = webdriver.Chrome(r'C:\Users\Hamza\Desktop\Python\chromedriver')
browser.get('https://facebook.com')

//Import csv file 
data = pd.read_excel (r'C:\Users\Hamza\Desktop\testcsv.xlsx')

2 Answers 2

1

I actually went on the Facebook website and pulled the source codes and wrote a little something extra quickly to log you in to the website

import pandas as pd
from selenium import webdriver
# Open Browser and go to facebook logging page
browser = webdriver.Chrome(r'C:\Users\Hamza\Desktop\Python\chromedriver')
browser.get('https://facebook.com')
# Import csv file 
data = pd.read_excel (r'C:\Users\Hamza\Desktop\testcsv.xlsx')
i = 0
while i == 0:
    a = 0
    Username = df.username
    Password = df.password

    # Sends username
    id_box = driver.find_element_by_class_id('email')
    id_box.send_keys(Username[a])
    # Sends password
    Pass_box = driver.find_element_by_class_name('pass')
    Pass_box.send_keys(Password[a])
    # Click login
    Send = driver.find_element_by_css_selector("u_0_3")
    Send.click()

    try:
        test = driver.find_element_by_class_name('pass')
        id_box.clear()
        Pass_box.clear()
    except:
        print("logged in")
        break
    a = a + 1

However this is assuming that your csv files has the files saved in columns named username and password, so you might have to tweak it

Sign up to request clarification or add additional context in comments.

3 Comments

That's exactly what i'm looking for ! Thank you so much ! But i had some errors, the first one is : while i = 0: SyntaxError: invalid syntax
Hi, I just edited my post, I was writing this very fast and didn't realize you actually have to use double equal signs when comparing a variable and a integer. Make sure to change that!
Thank you so much for your help Bob, now the code is running , it opens browser with facebook , select email input and then error : Username = df.username NameError: name 'df' is not defined
0

The best way to do this in my opinion is to open the CSV file in dict(). Here's my code it may help you guys. Ignore detail this is nothing just the file I'm working on.

with open('C:\Users\Hamza\Desktop\testcsv.csv','rt')as f:
    data = csv.DictReader(f)
    for detail in data:
        numberOfBedrooms=detail['numberOfBedrooms']
        numberOfBathrooms=detail['numberOfBathrooms']
        pricePerMonth=detail['pricePerMonth']
        adress=detail['adress']
        description=detail['description']
        square_feet=detail['square_feet']
        bedrooms = driver.find_element_by_xpath('//*[@id="jsc_c_12" or text()="Number 
        of bathrooms"]')
        bedrooms.send_keys(numberOfBathrooms)
        
       

Loop through your data and store the data you want in variable then use variable to sendeys. Just like I did in example bedrooms.send_keys(numberOfBathrooms)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.