【发布时间】:2016-02-28 19:32:40
【问题描述】:
我正在编写一个 python 脚本,其目的是从给定的网页中获取包含某个单词的所有链接。
www.example.com/about/someone
www.example.com/profile/someone
www.example.com/about/someone2
因此代码应该只获取那些包含单词about 的链接。
我收到以下错误:
"AttributeError: 'WebElement' object has no attribute 'get' "
这是我的代码:
driver.get("http://example.com/mypage")
time.sleep(20)
links = driver.find_elements_by_tag_name("a")
for link in links:
if '/about/' in link.get( 'href' ):
print (link.get_attribute("href"))
【问题讨论】:
-
使用
if '/about/' in link.get_attribute('href') -
我收到此错误 TypeError: 'NoneType' 类型的参数不可迭代
标签: python python-3.x selenium