我正试图从中提取href和数据名
我尝试了下面的代码,但只能在类“promo focus”下提取href,但我还想从data-promoname
中获取COVID-19 Economic cases: Scenarios for business leaders
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实现这一点吗
要从数据名中获取值,可以使用获取属性方法。此方法可用于获取与其标记对应的任何属性的值
如果要查找页面上锚定标记下显示的内容,可以使用.text
尝试使用text方法获取文本
示例
相关问题 更多 >
编程相关推荐