gpt4 book ai didi

python - 为什么 Python 无法请求解析 TikTok API 数据?

转载 作者:行者123 更新时间:2023-12-01 21:31:00 27 4
gpt4 key购买 nike

我正在使用请求库向 TikTok 发出 Python 请求。我设法挖掘了他们的用户详细信息的 URL(我不知道这是否合法。如果不合法,请告诉我)。当我尝试将其解析为 json 时,它会引发异常。有人可以帮我解析/解决这个问题吗?这是代码:Python 代码:

r1 = requests.get("https://www.tiktok.com/node/share/user/@nike?isUniqueId=true&verifyFp=verify_kb51zknj_GH98fcme_eDuR_4XzM_ATwp_s8TRdCzr8fwi&_signature=KBbp4AAgEBCtR.e4r-y0ZSgWqPAAHbR").json()
print(r1)

输出:

File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

谢谢

最佳答案

您必须提供用户代理 header ,即

headers = {
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
}

r1 = requests.get("https://www.tiktok.com/node/share/user/@nike?isUniqueId=true&verifyFp=verify_kb51zknj_GH98fcme_eDuR_4XzM_ATwp_s8TRdCzr8fwi&_signature=KBbp4AAgEBCtR.e4r-y0ZSgWqPAAHbR", headers=headers).json()
print(r1)

对不起,我试图将其作为评论发布,但未能格式化代码 xD

关于python - 为什么 Python 无法请求解析 TikTok API 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62396235/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com