尝试使用Python和BeautifulSoup解析网页以查找最新的高级漏洞

2024-10-02 12:29:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图应用其他人的建议:

Beautiful Soup: Accessing <li> elements from <ul> with no id

但我不能让它工作。看来那个问题的人 'parent'h2头,但我试图解析的那个没有。你知道吗

这是我正在刮的网页:

https://nvd.nist.gov/

(我想)我找到了我需要操纵的元素,它是<ul id="latestVulns">和它下面的li部分。你知道吗

我基本上是想勉强找到“最近20个得分的漏洞ID和摘要”一节,并根据漏洞是什么,向我工作场所的相应部门发送电子邮件。你知道吗

以下是我目前的代码:

from bs4 import BeautifulSoup
import requests

source = requests.get('https://nvd.nist.gov/')
soup = BeautifulSoup(source.content, 'lxml')

section = soup.find('latestVulns')
print(section)

此代码不返回任何值

我不知所措


Tags: 代码fromhttpsimportidsourceliul
2条回答

find的第一个参数需要元素的名称,您正在传递id。你知道吗

您可以使用它来正确地查找标记

section = soup.find('ul', {'id': 'latestVulns'})

find的第一个参数需要元素的名称,您正在传递id。你知道吗

您可以使用它来正确地查找标记

section = soup.find('ul', {'id': 'latestVulns'})

相关问题 更多 >

    热门问题