用python抓取etoro

2024-09-27 09:33:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Selenium自动连接到我的etoro帐户,并从我的投资组合中获取一些数据。我在谷歌Colab上工作,从现在起,我有:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')

wd = webdriver.Chrome(options=options)
wd.get("https://www.etoro.com/fr/login")

username = "username@mail.com"
password = "password"

elementID = wd.find_element_by_css_selector("input[automation-id='login-sts-username-input']")
elementID.send_keys(username)
elementID = wd.find_element_by_id("password")
elementID.send_keys(password)

但是,我有这个错误消息

Message: no such element: Unable to locate element: {"method":"css selector","selector":"input[automation-id='login-sts-username-input']"}
  (Session info: headless chrome=91.0.4472.77)

我曾尝试更改并使用按类查找元素、按xpath查找元素等,但我找不到如何做到这一点

你能帮我一下吗


Tags: addidinputusernameloginpasswordelementargument
2条回答

看看这是否有效:-

driver.find_element_by_xpath(".//input[@id='username']")

如果您不需要使用headless模式运行,删除该参数可以解决此问题。无论如何,这就是你的问题所在

我怀疑在无头浏览器模式下,我们可能会遇到某种机器人检测。如果你需要无头跑步,也许我们可以找到一个解决方法

相关问题 更多 >

    热门问题