![](/img/trans.png)
[英]NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="header3_5"]"}
[英]NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="my id"]"}
这是您获取 email 地址的方式:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time as t
chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument('disable-notifications')
chrome_options.add_argument("window-size=1280,720")
webdriver_service = Service("chromedriver/chromedriver") ## path to where you saved chromedriver binary
browser = webdriver.Chrome(service=webdriver_service, options=chrome_options)
url = 'https://temp-mail.org'
browser.get(url)
email_field = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, "mail")))
email_field.click()
t.sleep(1)
email_address = email_field.get_attribute('value')
print('email address:', email_address)
终端打印的结果:
email address: berini1082@zfobo.com
Selenium 设置是针对 linux 的,但是你只需要观察导入,以及定义浏览器之后的部分。 Selenium 文档位于https://www.selenium.dev/documentation/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.