温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python爬取主播信息

发布时间:2020-06-27 08:51:23 来源:网络 阅读:597 作者:九月朦胧 栏目:编程语言

之前学过python的爬虫技术,现在回顾一下看看还会不会,果然有坑。

先爬取了微博评论网友的id
代码如下

import requests
url = 'https://m.weibo.cn/api/comments/show?id=4188633986790962&page=6
h = requests.get(url)
print(h.json()['data']['data'][0]['user']['id'])

执行的时候报错
Traceback (most recent call last):
File "e:/personal/vscode/pameinv.py", line 9, in <module>
print(a())
File "e:/personal/vscode/pameinv.py", line 8, in a
return html.json()
File "D:\python\Python37\lib\site-packages\requests\models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "D:\python\Python37\lib\json__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "D:\python\Python37\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "D:\python\Python37\lib\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)
于是开始各种调试 最后换了一个地址行了,可能是微博的api不让调用了
于是修改了一下程序

import requests
url = 'http://www.yy.com/api/yyue-spot-news'
h = requests.get(url)
for j in range(len(h.json()['data'])):
print(h.json()['data'][j]['id']) #这里有缩进

print里的内容是根据网页里的相应信息而定的
python爬取主播信息

最后运行了一下 成功显示了主播的id
python爬取主播信息

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI