我制作了一个不和谐的机器人,它使用 selenium 访问网站并获取信息,当我在本地运行代码时,我没有任何问题,但是当我部署到 Heroku 时,我得到的第一个 URL 将我重定向到 page Attention Required! | Cloudflare。
我努力了:
还有许多其他具有我使用的相同设置的:
options = Options()
options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
options.add_experimental_option("excludeSwitches", ["enable-logging", "enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("--headless")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
self.driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), options=options)
self.driver.execute_cdp_cmd('Network.setUserAgentOverride', {
"userAgent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.53 Safari/537.36'})
Run Code Online (Sandbox Code Playgroud)
但这不起作用,代码仅在本地运行
PS:本地我在Windows上
我重定向到的页面来源:
https://gist.github.com/rafalou38/9ae95bd66e86d2171fc8a45cebd9720c
