2017-04-05 79 views
-2

我試圖做一個請求,並得到它們是div標籤等內的所有字符串內文本:Python中得到「格」標籤

  <div class='td allow_tip ' ><h3><a href='/exploit/description/25950'>WordPress Userpro Remote File Upload Exploit</a></h3> 

如何與Python做呢? THX

回答

0

假設你已經使用requests獲得html_source並將其存儲在變量s,您可以使用下面的代碼以提取所需的標籤(在本例a tags)文字:

代碼:

from bs4 import BeautifulSoup 

s = "<div class='td allow_tip ' ><h3><a href='/exploit/description/25950'>WordPress Userpro Remote File Upload Exploit</a></h3>" 

soup = BeautifulSoup(s, 'html.parser') 

a_tags = soup.find_all('a') 
for a in a_tags: 
    print(a.text) 

輸出:

'WordPress Userpro Remote File Upload Exploit'