我有一个充满Urls的文件(大约3000个网址),要求是在浏览器选项卡中调用每个网址,然后单击每个页面(只需在加载的页面上单击即可),然后重定向到不同的页面。这就是我要做的。
我已经为URL编写了一个代码,以使其一个接一个地检索并在页面上发生链接(该页面旨在单击任何位置以登陆或重定向到其他页面)。但是,在运行代码时,“无效参数”会引发错误。有什么想法,我该如何纠正错误?
感谢您的支持。
with open(dataFile, 'r') as urlFile:
urlFile.readline()
for url in urlFile:
driver = webdriver.Chrome('C:\\chromedriver_win32\\chromedriver.exe')
driver.get(url)
link = driver.find_element_by_xpath("/html/body")
link.click()
urlFile.close()
上面的代码应在新的浏览器选项卡上从文件中提取每个URL,然后单击。重复相同的操作,直到文件中的所有URL完成。
答案 0 :(得分:6)
我做了这样的事情 代码
from selenium import webdriver
import time
driver = webdriver.Chrome('driver_location')
f = open("dataFile.txt", 'r')
for line in f:
driver.get(line)
link = driver.find_element_by_css_selector("#header > div:nth-child(3) > div > div > div:nth-child(3) > div > a")
link.click()
print(driver.current_url)
f.close()
dataFile.txt文件中的网址
http://automationpractice.com/index.php
http://automationpractice.com/index.php
http://automationpractice.com/index.php
输出
http://automationpractice.com/index.php?controller=order
http://automationpractice.com/index.php?controller=order
http://automationpractice.com/index.php?controller=order
希望这会有所帮助。