首页 > 解决方案 > 使用 selenium 和 chromedriver 无法在 Heroku 上加载 Instagram 登录页面

问题描述

我正在尝试使用 selenium 和 chromedriver 登录 Instagram。驱动程序能够打开登录页面并输入用户名和密码,并且在我的本地 macOS 机器上登录成功。但是当我将它部署到 Heroku 时,它在用户名字段上显示 NoSuchElement。

这是我的代码。

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("user-agent=Mozilla/5.0 (X11; Ubuntu; Linux armv7l; rv:17.0) Gecko/20100101 Firefox/17.0")
driver_path = ChromeDriverManager().install()
driver = webdriver.Chrome(driver_path, chrome_options=chrome_options)
driver.implicitly_wait(60)

driver.get('https://www.instagram.com/')
username_input = WebDriverWait(browser, 60).until(EC.visibility_of_element_located((By.XPATH, "//input[@name='username']")))
password_input = browser.find_element_by_css_selector("input[name='password']")

username_input.send_keys("test")
password_input.send_keys("test")

login_button = browser.find_element_by_xpath("//button[@type='submit']")
login_button.click()

seleniumwire我使用和早些时候打开 Instagram 登录 url跟踪我的请求给 301,但添加后user agent我现在得到 200 的 Instagram 登录 url。

但现在它无法找到用户名输入字段。

PS - 这在本地 macOS 机器上工作正常,但不能在Heroku

标签: pythonseleniumselenium-webdriverherokuselenium-chromedriver

解决方案


推荐阅读