Chromedriver 中的 404 错误,但 Chrome 中没有

404 Error in Chromedriver, but not in Chrome

提问人:Ashley Southworth 提问时间:11/9/2023 更新时间:11/9/2023 访问量:28

问:

开始一个新问题,因为以前的问题似乎情况略有不同。

我有一个网站(由于它是公司项目,我无法共享 URL),我可以通过网络上的 google chrome 访问它,但我无法通过远程服务器上运行的 chromedriver 访问它。

服务器没有运行防火墙。服务器也没有使用代理,我的本地机器也没有。

我用于启动 selenium 的 selenium 代码如下所示,并且在页面上运行 driver.get() 之前被调用。

def start_selenium(
        headless=True,
        data_dir=None,
        profile=None,
        cloudflare=False,
        download_dir=1,
        use_proxy=False,
    ):

    if cloudflare:
        chrome_options = uc.ChromeOptions()
    else:
        chrome_options = webdriver.ChromeOptions()

    chrome_options.add_argument('--web-security=false')
    chrome_options.add_argument('--ssl-protocol=any')
    chrome_options.add_argument('--ignore-ssl-errors=yes')
    chrome_options.add_experimental_option('prefs', {'plugins.always_open_pdf_externally': True})

    if headless:
        chrome_options.add_argument('--no-sandbox')
        chrome_options.add_argument('--headless')
        chrome_options.add_argument('--disable-gpu')
        chrome_options.add_argument('--disable-dev-shm-usage')
        chrome_options.add_argument('--log-level=3')
        chrome_options.add_argument("--window-size=700,1080")
        chrome_options.add_argument("--enable-javascript")
        chrome_options.add_argument('--ignore-certificate-errors')
        chrome_options.add_argument('--disable-breakpad')
        chrome_options.add_argument(f"--service_log_path={os.path.devnull}")
        chrome_options.add_argument("--disable-extensions")
        chrome_options.add_argument('--disable-application-cache')
        chrome_options.add_argument("--disable-setuid-sandbox")

    selenium_logger = logging.getLogger('seleniumwire')
    selenium_logger.setLevel(logging.ERROR)

    if use_proxy and proxy:
        print("USING PROXY:", proxy.full)
        proxy_dict = {
            'proxy': {
                'http': proxy.full,
                'https': proxy.full,
                'no_proxy': 'localhost, 127.0.0.1'
            }
        }
    else:
        print("NO PROXY")

    if cloudflare:
        # from seleniumwire.undetected_chromedriver.v2 import (
        #     Chrome as UCChromeWire,
        # )  # lazy load

        from undetected_chromedriver import Chrome as UCChrome

        print(r"Attempting to allocate UC Chrome (Wire) webdriver...")

        chrome_path = f"folder/chrome-linux64/chrome"
        chromedriver_path = f"folder/chromedriver-linux64/chromedriver"

        chrome_options.binary_location = chrome_path

        driver = UCChrome(
            debug=True,
            options=chrome_options,
            use_subprocess=True,
            seleniumwire_options=proxy_dict,
            browser_executable_path=chrome_path,
            driver_executable_path=chromedriver_path,
            version_main=117,
            # user_multi_procs=True,
        )
    else:
        from seleniumwire.webdriver import Chrome  # lazy load

        driver = Chrome(
            chrome_options=chrome_options,
            seleniumwire_options=proxy_dict,
        )


    return driver

这不会发生在每个页面上,我能够加载像谷歌这样的网站。

谢谢!我正在寻找可能导致此问题的 chrome 的任何原因或错误配置。有没有可能是一些网站制作的新的反抓取机制?

谷歌-chrome selenium-webdriver selenium-chromedriver

评论


答: 暂无答案