0

trying to do this on Instagram. there is code before it like importing the libraries and chrome driver path and logging in..so below is the loop that is failing...what's your suggestion? it works when I put in a list of exact URLs..so there is definitely something wrong in the loop

users=['instagramuser1','instagramuser2','instagramuser3']
user=-1
for user in users:
    user+=1
    webdriver.get('https://www.instagram.com/'+str(users)+'/')
    sleep(5)
    webdriver.find_element_by_css_selector('the_amazing_css_path').click()
Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48

2 Answers2

0

I think what you want is:

users=['instagramuser1','instagramuser2','instagramuser3']

for user in users:
    webdriver.get('https://www.instagram.com/' + user + '/')
    sleep(5)
    webdriver.find_element_by_css_selector('the_amazing_css_path').click()

Note user instead of users in the URL string.

Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48
  • thanks...how do i make it pull from a csv file instead? would this work: users=" C:\Users\Downloads\xyz.csv" – chandru Sep 09 '19 at 11:28
  • No, it won't. Read [How to read a file in Python](https://stackoverflow.com/questions/3277503/how-to-read-a-file-line-by-line-into-a-list) – Yevhen Kuzmovych Sep 09 '19 at 14:02
0

I assume you use exact code posted in the question. so you did not follow python indent rule in this particular code it sould be fix like this:

users=['instagramuser1','instagramuser2','instagramuser3']
for user in users:
    webdriver.get('https://www.instagram.com/'+user+'/')
    sleep(5)
    webdriver.find_element_by_css_selector('the_amazing_css_path').click()
A.J
  • 54
  • 5