用蟒蛇刮埃托罗



我正试图使用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)

我尝试过更改和使用find_element_by_class、by_xpath等,但我找不到如何做到这一点

你能帮我一下吗?

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

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

看看这是否有效:-

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

为了完整起见,Selenium在4.3.0版本中删除了一些方法,因此您的代码应修改为:

...
elementID = wd.find_element("xpath",".//*[@id='username']")
...
elementID = wd.find_element("id","password")
...

请参阅AttributeError:';WebDriver';对象没有属性';find_element_by_xpath';

最新更新