【发布时间】:2021-02-26 18:09:44
【问题描述】:
我制作了一个使用 selenium 访问网站并获取信息的不和谐机器人,当我在本地运行我的代码时我没有任何问题,但是当我部署到 Heroku 时,我得到的第一个 URL 将我重定向到页面 @ 987654327@.
我试过了:
还有许多其他的设置与我使用的相同:
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'})
但这不起作用,代码只能在本地运行
PS:本地我在 Windows 上
我被重定向到的页面来源: https://gist.github.com/rafalou38/9ae95bd66e86d2171fc8a45cebd9720c
【问题讨论】:
-
您被重定向到的页面的内容是什么?会不会是 Cloudflare 的 WAF 挑战你证明你是人类而不是机器人?
-
您可能希望在 Cloudflare 页面规则中将 Heroku 机器的 IP 地址列入白名单,这样它就不会触发验证码检查。看到这个答案stackoverflow.com/questions/50328849/…
标签: python selenium heroku captcha cloudflare