我正在寻找该网络元素的文本
<span class="address what_to_copy">thisemail@changes.com</span></h1>
该元素是一封不断变化的电子邮件。如何集成get_attribute()
。
目前,硒给我:
<selenium.webdriver.remote.webelement.WebElement (session="163f197aa61b4cfbc9962b5b746aa225", element="0.1826725098009514-1")>
从下面的代码
#coding: utf-8
import time
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
class WebDriver:
def __init__(self):
self.setup()
self.extractor()
self.teardown_module()
def setup(self):
self.options = Options()
self.options.headless = True
self.driver = webdriver.Chrome('/Users/user/Documents/docs/chromedriver', options=self.options)
def extractor(self):
self.driver.get('https://getnada.com/')
print('\n')
sauce = self.driver.page_source
element = self.driver.find_element(By.CSS_SELECTOR, 'span.address.what_to_copy')
print(element.text)
def teardown_module(self):
self.driver.quit()
page = WebDriver()
page.driver
答案 0 :(得分:1)
text
包含元素的值
element = self.driver.find_element(By.CSS_SELECTOR, 'span.address.what_to_copy')
print(element.text)