【发布时间】:2021-01-18 04:40:56
【问题描述】:
美好的一天。我是网络抓取自动化的新手,刚刚开始对包碎片进行一些测试。 我的工作环境如下:
- 操作系统:Ubuntu20.04(在 Windows10 上,无 gui)
- IDE:Vscode
- 语言:Python
- 包:splinter 0.14.0
我正在关注一些教程并执行以下代码,它们可以完美运行:
from splinter import Browser
executable_path = {"executable_path" : r'/usr/local/bin/chromedriver'}
browser = Browser(driver_name = 'chrome', **executable_path, headless =True)
browser.visit('https://www.google.com')
print(browser.title)
# return Google
browser.quit()
但是,当我尝试使用 https://tw.yahoo.com/?p=us 等其他网站时,系统卡住了 一会儿,返回错误信息如下:
File "/home/stevetsaoch/Tradebot/main.py", line 23, in <module>
browser.visit('https://tw.yahoo.com/?p=us')
File "/home/stevetsaoch/.local/lib/python3.8/site-packages/splinter/driver/webdriver/__init__.py", line 287, in visit
self.driver.get(url)
File "/home/stevetsaoch/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/home/stevetsaoch/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/stevetsaoch/.local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from renderer: 299.850
(Session info: headless chrome=87.0.4280.141)
根据我的理解,上面的消息表明我的 chrome 无法找到 https://tw.yahoo.com/?p=us 并且在搜索默认时间段后它返回超时错误。顺便说一句,我同时在 Windows 上用我的 chrome 检查了https://tw.yahoo.com/?p=us,它会在很短的时间内做出响应。 对于这种情况有什么建议吗?任何建议或意见表示赞赏。
【问题讨论】:
-
顺便说一句,当我在 Windows 10 上使用 python shell 并运行相同的代码时,访问tw.yahoo.com/?p=us,代码运行良好。
标签: python web-scraping timeout splinter