Selenium如何提取Python的href和标签名?

Bangbangbang

我试图从中提取href和数据促销名称

网址:https//www2.deloitte.com/global/zh/pages/about-deloitte/topics/combating-covid-19-with-resilience.html?icid = covid-19_article-nav

在此处输入图片说明

我尝试了下面的代码,但只能在“ promo-focus”类下提取href,但是我也想COVID-19 Economic cases: Scenarios for business leadersdata-promoname

driver = webdriver.Chrome(executable_path=r'C:\chromedriver.exe')
url = "https://www2.deloitte.com/global/en/pages/about-deloitte/topics/combating-covid-19-with-resilience.html?icid=covid-19_article-nav"
driver.get(url)

for i in driver.find_elements_by_class_name('promo-focus'):
    print(i.get_attribute('href'))

谁能告诉我如何使用Python做到这一点?

0立方米

尝试使用text方法获取文本。

from selenium import webdriver

chrome_browser = webdriver.Chrome()
url = "https://www2.deloitte.com/global/en/pages/about-deloitte/topics/combating-covid-19-with-resilience.html?icid=covid-19_article-nav"
chrome_browser.get(url)
for a in chrome_browser.find_elements_by_class_name('promo-focus'):
    print(a.get_attribute('href'))
    print(a.text)

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用 Selenium 和 Python 通过 href 提取文本

如何使用 Selenium 和 Python 根据标签名称和属性查找 Web 元素

如何使用Selenium和Python提取第一个搜索结果的href属性

如何使用 Selenium 和 Python 从特定类中提取 href 信息

如何在Selenium Python中获取标签名称?

从href标签selenium webscraper中提取html

如何从Python Selenium中的类提取所有href?

获取标签名称Selenium python

按 Selenium Python 类提取 href

使用 selenium 从标签中提取名称或 href 无需点击

如何使用Selenium和Python获取元素的href属性

如何从a标签中提取所有href,并测试它们是否以'/'开头或不使用beautifulsoup?-Python

如何使用Selenium和Python从HTML提取文本

如何使用Python和Selenium提取特定数据

如何使用Selenium和Python从标记属性中提取数据?

如何使用 Selenium 和 Python 提取小計價格

如何使用Selenium WebDriver和Python提取元素内的文本?

如何使用Selenium和Python从div类中提取文本

如何使用 Selenium 和 Python 从 webelements 中提取文本

如何使用Selenium和python查找aria标签

如何使用 selenium 和 python 抓取 div 标签内的标签标签中的文本值?

从 python selenium 中的标签名称获取文本

如何使用xpath和python提取包含不需要的BR标签的标签之间的文本?

如何在Selenium Web Automation(Python)中遍历Web元素以从HTML标签提取文本?

Python selenium - 获取文本和href

使用 Selenium 和 Python 獲取 href

如何使用Selenium从搜索结果中提取Google链接的href?

Selenium 如何从属性中提取href

Python / Selenium-无法获取标签的HREF值