Python 代码不会使用 selenium 循环浏览网站
我有一个带有商品编号的 Excel 工作表,想要循环遍历 Excel 电子表格中的每一行,并使用 selenium 在网站上搜索产品价格,然后将产品价格写入同一个电子表格中,但不知何故,循环不起作用
希望你能帮助我
'''
lastrow= 10
indx = 2
Artikelnumber = sheet.cell(row=indx, column=2).value
while indx > lastrow:
#Search
search_txt = driver.find_element(By.ID, 'suggestSearch')
search_txt.click()
#Number
search_txt.send_keys(Artikelnumber)
search_txt.send_keys(Keys.ENTER)
#Produktpreis
Produktpreis = driver.find_element(By.XPATH, '(//span[@class="priceValue "])[1]' ).text
workbook = load_workbook(filename='test.xlsx')
sheet = workbook["test"]
sheet.cell(row=indx, column=8).value = Produktpreis
indx = indx + 1
'''
i have a Excel sheet with article numbers and want to loop through each row in the excel spreadsheat and search the product price on a website with selenium and afterwards write the product price to the same spreadsheet but somehow the loop doenst work
Hopefully u can help me
'''
lastrow= 10
indx = 2
Artikelnumber = sheet.cell(row=indx, column=2).value
while indx > lastrow:
#Search
search_txt = driver.find_element(By.ID, 'suggestSearch')
search_txt.click()
#Number
search_txt.send_keys(Artikelnumber)
search_txt.send_keys(Keys.ENTER)
#Produktpreis
Produktpreis = driver.find_element(By.XPATH, '(//span[@class="priceValue "])[1]' ).text
workbook = load_workbook(filename='test.xlsx')
sheet = workbook["test"]
sheet.cell(row=indx, column=8).value = Produktpreis
indx = indx + 1
'''
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从这个问题你必须使用 openpyxl 模块
下面的代码将帮助你解决你的问题
希望这会有所帮助
From this problem you have to use openpyxl module
Below code will help you to solve your problem
Hope this will Help