我有一个 .txt 文件中的 URL 列表,我想使用 selenium 运行它。
假设文件名为 b.txt,其中包含 2 个 url(精确格式如下): https://www.google.com/,https://www.bing.com/,
我想要做的是让 selenium 运行两个 url(来自 .txt 文件),但是似乎每次代码到达“driver.get”行时,代码都会失败。
url = open ('b.txt','r')
url_rpt = url.read().split(",")
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=options)
for link in url_rpt:
driver.get(link)
driver.quit()
Run Code Online (Sandbox Code Playgroud)
我运行代码时得到的结果是
Traceback (most recent call last):
File "C:/Users/ASUS/PycharmProjects/XXXX/Test.py", line 22, in <module>
driver.get(link)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38\lib\site-
packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38\lib\site-
packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python38\lib\site-
packages\selenium\webdriver\remote\errorhandler.py", line 242, in
check_response
raise …Run Code Online (Sandbox Code Playgroud)