python3利用爬虫从https://cve.mitre.org网站获取漏洞信息
import requests
from bs4 import BeautifulSoup
import logging
logging.basicConfig(level=logging.INFO, # 设置日志级别
format='%(asctime)s - %(filename)s(%(lineno)d)[%(levelname)s]: %(message)s')
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0",
}
def get_cve_info(cve_id):
"""
:type cve_id: str
:return:
"""
res = requests.get("https://cve.mitre.org/cgi-bin/cvename.cgi?name=%s" % cve_id, headers=headers)
html = res.content.decode("utf-8")
bs = BeautifulSoup(html, "html.parser")
tag_tr_td = list(bs.find(id="GeneratedTable").table.children)[7]
cve_info = list(tag_tr_td.children)[1]
return cve_info.strip()
if __name__ == "__main__":
cve_info = get_cve_info("CVE-2003-0109")
logging.info(cve_info)