簡體   English   中英

如何使用Selenium和python從網頁獲取特殊單詞的鏈接?

[英]How to get link with special word from webpage using selenium and python?

我正在研究一個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"))
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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM