将ID,Class或Name的值保存到变量中。蟒蛇

I want to save the Email from 10minutemail.net into a variable with Python. My Code:

from selenium import webdriver
from time import sleep

driver = webdriver.Chrome(r'''C:\WebDriver\chromedriver.exe''') #set driver
email = "" #get from 10minutemail.net

driver.get("https://10minutemail.net")
sleep(2)
#get the email and save it into 'email'
email = driver.find_element_by_id('fe_text')

我也试过这个:

email = driver.find_element_by_id('fe_text').value()

但这也不起作用。那么如何将电子邮件保存到变量中?

评论
简小兮
简小兮

您快到了。如果您查看网页上的HTML元素,则其外观类似于:

<input type="text" id="fe_text" class="mailtext" value="xkb21056@zzrgg.com">

Notice that the email is actually a HTML attribute. I don't think there's a .value() (I got an error when I did that) but I know you can retrieve the attribute using get_attribute():

email = driver.find_element_by_id('fe_text').get_attribute("value")
点赞
评论
㈠个
㈠个

你可以试试

driver.find_element_by_css_selector("#fe_text").get_attribute("value")
点赞
评论