[英]how do I print the contents of a <cite>?
我试图拉出与谷歌提供的 python 的链接,以及为什么它不起作用。 错误:
AttributeError: 'WebElement' object has no attribute 'text'
我的代码:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
input = input('what do you want to *scrape* ?\n>')
driver = webdriver.Opera()
driver.get('https://google.com')
print(driver.title)
search = driver.find_element_by_xpath('//*[@id="tsf"]/div[2]/div[1]/div[1]/div/div[2]/input')
search.send_keys(input)
search.send_keys(Keys.RETURN )
headers = driver.find_elements_by_tag_name('h3')
cites = driver.find_elements_by_tag_name('cite')
for cite in cites :
print(cite.text)
time.sleep(5)
print('done')
driver.quit()
我刚刚运行了您的代码,并且在提供了 Operadriver 可执行文件的路径后它运行良好
driver = webdriver.Opera(executable_path=r"C:\operadriver.exe)
尝试 cite.getAtrribuet("innerHTML") 或 cite.getAttribute ("outterHTML") 或 excuter.executeScript("arguments[0].innerHTML",cite) 或将内部替换为外部
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.