python - 页面加载后如何使硒刮页面
问题描述
我正在使用 scrapy 来抓取所有链接,并使用 selenium 来抓取所有页面。Selenium 刮掉了大部分页面,但由于页面加载需要时间而留下了一些页面。
我尝试了 timeout() ,但似乎没有用,然后我尝试了 execute_script
driver.execute_script("return document.readyState=="complete";")
这似乎也不起作用,然后我尝试了 expected_conditions
WebDriverWait.until(expected_conditions.execute_script("return document.readyState=="complete";"))
但似乎没有用
我正在使用 firefox 浏览器,用于 Headless 的 phantomJs 尝试使用 Chrome 驱动程序安装,brew cask install chromedriver
但我遇到了这个错误
raise WebDriverException("Can not connect to the Service %s" % self.path) selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver
所以回到phantomjs。
谢谢!
解决方案
raise WebDriverException("Can not connect to the Service %s" % self.path) selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver
这是因为您的程序无法通过给定的 chromedriver.exe 连接到服务,这可能是由于版本不匹配或可执行文件不可用而发生的。
您可以按如下方式解决它:
检查您在系统上使用的 chrome 浏览器的版本,您可以在 chrome 设置 > 关于 chrome 中查看。然后在此处相应地下载 chromedriver: https ://chromedriver.chromium.org/downloads
您可以将其存储在任何地方,但最好将其保存在与代码相同的目录中。将其解压缩并将其复制到相应的目录中,您就可以使用 chromedriver。
如果它与您的程序不在同一目录中,请取消注释
driver = webdriver.Chrome()
或使用。driver = webdriver.Chrome(executable_path=r'your path here')
推荐阅读
- python - Pandas 从查找 DataFrame 列中减去 DataFrame 列
- pandas - Pandas DataFrame groupby,跨列计数和求和
- azure - 无法部署 Azure Function App - 存储帐户错误
- vue.js - vue3:具有定时功能的控制属性
- python - 执行 client.run() 后如何运行 discord 机器人?
- javascript - 将 maximo spatial 的新自定义小部件添加到地图工具栏
- json - 如何在 Django 中通过 URL 引入 JSON 文件?
- php - Botman Studio 不回复
- multithreading - 一个程序中的线程数
- c - 将逗号分隔的文本文件读入结构 C