首页 > 解决方案 > Python 3 - 带有 JSONDecodeError 的 Web 抓取 Microsoft CVE 网页错误

问题描述

所以,我读了下面的问题。答案提供了一些代码供进一步测试。

如何浏览动态分配其内容的 Microsoft CVE 网页(最好使用 Python)?

这是我的代码的执行。有人可以就下面的错误代码提供建议吗?

Python 3.6.8 (default, Sep 26 2019, 11:57:09)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>>
>>> cve_url = "https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2020-0910"
>>>
>>> response = requests.get(cve_url)
>>> cve_dict = response.json()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib64/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 2)

>>> print(response.text)

该网站有回应。响应文本可在此处获得。

https://ybin.me/p/4302365fe913f62c#sdm8+KPnPhPQ8NfX9rrb2LuLgWUm5RgrnNSvd9Rtfd8=

谢谢你。

标签: pythonjsonpython-3.xweb-scraping

解决方案


即使我使用以下网址也遇到了同样的错误

https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2018-8176

后来我尝试以下示例下载带有 CVE 数据的 Json。希望这可以帮助:

import json
import requests
from bs4 import BeautifulSoup

url = (
    "https://api.msrc.microsoft.com/sug/v2.0/en-US/vulnerability/CVE-2018-8176"
)

data = requests.get(url).json()

# uncomment to print all data:
# print(json.dumps(data, indent=4))

print(data["cveTitle"])
print(BeautifulSoup(data["description"], "html.parser").get_text(strip=True))

输出:

Microsoft PowerPoint Remote Code Execution Vulnerability
A remote code execution vulnerability exists in Microsoft PowerPoint software when the software fails to properly validate XML content. An attacker who successfully exploited the vulnerability could run arbitrary code in the context of the current user. If the current user is logged on with administrative user rights, an attacker could take control of the affected system. An attacker could then install programs; view, change, or delete data; or create new accounts with full user rights. Users whose accounts are configured to have fewer user rights on the system could be less impacted than users who operate with administrative user rights.Exploitation of the vulnerability requires that a user open a specially crafted file with an affected version of Microsoft Office PowerPoint software. In an email attack scenario, an attacker could exploit the vulnerability by sending the specially crafted file to the user and convincing the user to open the file. In a web-based attack scenario, an attacker could host a website (or leverage a compromised website that accepts or hosts user-provided content) that contains a specially crafted file designed to exploit the vulnerability. An attacker would have no way to force users to visit the website. Instead, an attacker would have to convince users to click a link, typically by way of an enticement in an email or instant message, and then convince them to open the specially crafted file. After the file is open, the user would need to move their mouse over a specific location on the page within the PowerPoint file to trigger the vulnerability.Note that the Preview Pane is not an attack vector for this vulnerability. The security update addresses the vulnerability by correcting how Microsoft PowerPoint handles objects in memory.

推荐阅读