繁体   English   中英

NoSuchElementException:消息:没有这样的元素:无法找到元素:{"method":"xpath","selector":"//*[@id="my id"]"}

[英]NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="my id"]"}

如何从受保护的网站复制文本? 如果您尝试按 xpath、名称和标签进行复制,则会出错。

这是我尝试使用 XPath 时遇到的错误(obs:网站内部有一个“复制”按钮,如果单击该按钮,则会复制文本)

在此处输入图像描述

这是我的代码:

在此处输入图像描述

网站上写着:不要再担心垃圾邮件、email 广告、黑客和机器人攻击了。 我认为这就是它给出错误的原因。 有人知道它是什么吗?

这是您获取 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.

相关问题 NoSuchElementException:消息:没有这样的元素:无法定位元素:{“method”:“xpath”,“selector”:“//* [@id =“header3_5”]”} NoSuchElementException:消息:没有这样的元素:无法找到元素:{"method":"css selector","selector":"[id="events_table"]"} 得到以下消息:没有这样的元素:无法定位元素:{“method”:”xpath”,”selector”:”//span[@id='lblError']/text()”}” selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{"method":"xpath","selector":""} 无法定位元素:{"method":"xpath","selector":"//input[@id='fieldname3_1']"} 无法找到元素 ID - NoSuchElementException 没有这样的元素:无法定位元素:{"method":"xpath","selector":"//*[@id="_id0:logon:USERNAME"]"} 消息:没有这样的元素:无法找到元素:{“method”:“css selector”,“selector”:“[id=”loginUsername“]”} 收到消息:没有这样的元素:无法找到元素:{"method":"css selector","selector":"[id="None"]"} Python 使用 selenium 时 Python: Selenium 没有这样的元素: 无法定位元素: {“method”:“xpath”,“selector”:“//button[@data-id=1]”}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM