爬虫
本文最后更新于322 天前,其中的信息可能已经过时,如有错误请发送邮件到3368129372@qq.com

以bilibili直播弹幕为例

导入相关库

import requests,json,time

设置请求头

url = 'https://api.live.bilibili.com/xlive/web-room/v1/dM/gethistory?roomid=26568219&room_type=0'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36',
    }

数据处理

response = json.loads(requests.get(headers=headers, url=url).text)
    response = response['data']['room']
    for i in response:
        text = i['text']
        name = i['nickname']
        timeline = i['timeline']
        result = f'[{timeline}] {name}: {text}'
        if result not in item:
            item.append(result)
            print(result)
        time.sleep(0.5)

将读取到的str类型(json)转化为dict数据,并从中取出想要的数据进行输出

感谢您的收看~
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇