-2
我試圖做一個請求,並得到它們是div標籤等內的所有字符串內文本:Python中得到「格」標籤
<div class='td allow_tip ' ><h3><a href='/exploit/description/25950'>WordPress Userpro Remote File Upload Exploit</a></h3>
如何與Python做呢? THX
我試圖做一個請求,並得到它們是div標籤等內的所有字符串內文本:Python中得到「格」標籤
<div class='td allow_tip ' ><h3><a href='/exploit/description/25950'>WordPress Userpro Remote File Upload Exploit</a></h3>
如何與Python做呢? THX
假設你已經使用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'