如何使用python和selenium webdriver刮取https网站数据

如何使用python和selenium webdriver刮取https网站数据,selenium,https,phantomjs,ssl-certificate,python-3.4,Selenium,Https,Phantomjs,Ssl Certificate,Python 3.4,一个多星期来我一直在努力拼搏,现在我已经在网上搜索了我的问题,但是我找不到合适的解决办法。所以我把我的问题贴在这里 这是我的webscraper代码。 from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.webdriver.support.ui import WebD

一个多星期来我一直在努力拼搏,现在我已经在网上搜索了我的问题,但是我找不到合适的解决办法。所以我把我的问题贴在这里

这是我的webscraper代码。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import sys
import lxml
import unittest, time, re

class Sel(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.PhantomJS(executable_path='\phantomjs.exe')#phantom js
        self.driver.implicitly_wait(30)
        self.base_url = "https://www.zomato.com"
        self.verificationErrors = []
        self.accept_next_alert = True
    def test_sel(self):
        driver = self.driver
        delay = 3
        driver.get(self.base_url + "hyderabad")
        driver.find_element_by_link_text("All").click()
        for i in range(1,100):
            self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
            time.sleep(4)
        html_source = driver.page_source
        data = html_source.encode('utf-8')


if __name__ == "__main__":
当我在python 3.4中运行时,即directory/py-3.4.py 我得到这个错误
.
有人能帮我解决这个问题吗?

致以最诚挚的问候。

您需要在请求中添加适当的接受编码头


“接受编码”:“gzip,deflate,sdch,br”

首先,您发布的错误屏幕截图不是来自您发布的代码。您的代码示例显示您正在调用
webdriver.PhantomJS
,但屏幕截图清楚地显示您在调用
webdriver.Firefox
时遇到了错误

另外,屏幕截图中的错误消息会准确地告诉您问题是什么以及如何解决它:“geckodriver可执行文件需要在路径中”

将Firefox与selenium结合使用。您需要安装geckodriver并使其在您的路径上可用。geckodriver(如chromedriver)是Firefox或Selenium不附带的外部组件。。。它必须单独安装


您可以在此处下载geckodriver:

Mate很抱歉,这与以前的错误不一样。粘贴错误消息中的文本,不要链接到屏幕截图。谢谢您的关注。