我正在制作一个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"))
答案 0 :(得分:0)
driver.get("http://example.com/mypage")
driver.implicitly_wait(20)
links = driver.find_elements_by_tag_name("a")
for link in links:
href = link.get_attribute('href')
if not href:
continue
if '/about/' in href:
print(href)