I have a code that I use to modify certain values of a URL. I explain the process, after login, I call another url in which I make changes. The problem is that I need to enter many URLs similar to these to do the same operation, the difference between the url is the ID (bold) link afebecf1-0bc3-4e1e-91ef-dc26de42aca7 / general. I want to enter the different IDs in the URL to be able to call all the URLs of the IDs
Those IDs I have in an Excel. What I'm looking for is to move them to a list (I think that's what's best for me) and to enter those ID values in the URL call to repeat the action I need. Capable with some function can be achieved.
import time
from selenium import webdriver
import csv
driver = webdriver.Chrome('/Users/Martin/Desktop/chromedriver')
driver.get("https://platform.io/en/login/")
user= driver.find_element_by_xpath('//*[@id="form_username"]')
user.send_keys("email")
passwd = driver.find_element_by_xpath('//*[@id="form_password"]')
passwd.send_keys("pass")
l_button = driver.find_element_by_xpath('//*[@id="login_submit"]')
l_button.click()
time.sleep(1)
driver.get("https://auto.io/en/users/inventory/afebecf1-0bc3-4e1e-91ef-dc26de42aca7/general")
time.sleep(1)
l_button = driver.find_element_by_xpath('//*[@id="inventory_general"]/fieldset/div[1]/div[2]/span/span[2]/span')
l_button.click()
Edit:
Trying to read the data of a CSV following the solution of the answer of FJSevilla I have found a new error. The csv has the following structure:
301d5e7b-a75f-4962-f38f-1e6e5db90dcc
f5b2b6ba-a4ce-4e17-b8f8-b8d912e4d6ec
7ed4aaa7-0b3f-44c6-f254-be986985942d
...
It's actually a single column as seen. The code with which I try to read it is:
import csv
with open("Ids para Pausar.csv", 'r') as my_file:
reader = csv.reader(my_file, delimiter=',')
my_list = list(reader)
for id in my_list:
url = "https://platform.io/en/users/inventory/{}/general".format(id.strip())
driver.get(url)
time.sleep(1)
l_button = driver.find_element_by_xpath('//*[@id="inventory_general"]/fieldset/div[1]/div[2]/span/span[2]/span')
l_button.click()
l_button = driver.find_element_by_xpath('//*[@id="form_submit"]')
l_button.click()
time.sleep(2)
driver.close()
But I get the following error:
AttributeError: 'list' object has no attribute 'strip'.