我试图用selenium webdriver打开来自TXT文件的URLS.But代码给了我error.Here是我使用python 3.4.3的代码。这个代码中可能有什么问题?
from selenium import webdriver
with open("vps.txt","r") as fi:
urls = fi.read().splitlines()
for url in urls:
browser = webdriver.Firefox()
browser.get(url)
我收到此错误:
Traceback (most recent call last):
File "C:\pselenium\browse.py", line 8, in <module>
browser.get(url)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 245, in get
self.execute(Command.GET, {'url': url})
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Target URL www.youtube.com/watch?v=DowtrQhvbUM is not well-formed.
Stacktrace:
at FirefoxDriver.prototype.get (file:///C:/Users/naV/AppData/Local/Temp/tmpja7hed7p/extensions/fxdriver@googlecode.com/components/driver-component.js:10636)
at DelayedCommand.prototype.executeInternal_/h (file:///C:/Users/naV/AppData/Local/Temp/tmpja7hed7p/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///C:/Users/naV/AppData/Local/Temp/tmpja7hed7p/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///C:/Users/naV/AppData/Local/Temp/tmpja7hed7p/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)
答案 0 :(得分:2)
Target URL www.youtube.com/watch?v=DowtrQhvbUM is not well formed
看起来您的文件编码存在问题。我不确定这是否是BOM,但您应该使用十六进制编辑器检查您的文件。