我正在尝试发出请求并获取div标签内的所有字符串等:
<div class='td allow_tip ' ><h3><a href='/exploit/description/25950'>WordPress Userpro Remote File Upload Exploit</a></h3>
如何用python做到这一点? THX
答案 0 :(得分:0)
假设您已使用requests
获取html_source
并将其存储在变量s
中,则可以使用以下代码提取所需标记的文本({{1}在示例中):
<强>代码:强>
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)