【发布时间】:2020-11-02 07:58:27
【问题描述】:
这是HTML源代码:
<div class="dropdown-popup">
<a href="/integrations/sources/" class="dropdown-item">Sources</a>
<a href="/integrations/destinations/" class="dropdown-item">Destinations</a>
<a href="/integrations/analysis-tools/" class="dropdown-item">Analysis</a>
</div>
我想访问Sources、 Destinations、Analysis 并将其存储在列表中。
我该怎么做,使用 selenium python?
这是我目前得到的
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://example.com")
tag_list = i.text.strip() for i in browser.find_elements_by_css_selector("div.dropdown-popup").find_elements_by_tag_name('a')
print(tag_list)
错误:
AttributeError: 'list' object has no attribute 'find_elements_by_tag_name'
【问题讨论】:
-
[i.text.strip() for i in driver.find_elements_by_css_selector("div.dropdown-popup").find_elements_by_tag_name('a)] -
tag_list = [i.text.strip() for i in browser.find_elements_by_css_selector("div.dropdown-popup"").find_elements_by_tag_name('a')]。错误:'list' 对象有没有属性“find_elements_by_tag_name”
标签: html python-3.x selenium selenium-webdriver css-selectors