当前位置: 移动技术网 > IT编程>脚本编程>Python > 荐 抖音综合榜单数据爬虫案例

荐 抖音综合榜单数据爬虫案例

2020年07月03日  | 移动技术网IT编程  | 我要评论

偶然在抖音创作平台中看到了一系列的排行榜,如热搜榜、热门视频榜、娱乐明星榜、音乐榜等等。

网页链接: https://creator.douyin.com/billboard/home 登陆后可见数据

在这里插入图片描述


榜单接口

接口名 类型 链接
热搜榜单 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=1
热点上升榜 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=9
今日热门视频 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=4
娱乐明星 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=2
体育热力 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=3
直播榜单 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=10
热歌榜 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=5
音乐飙升榜 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=6
原创音乐榜 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=7
二次元榜单 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=61
搞笑榜单 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=86
旅行 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=91
剧情 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=81
美食榜 Get https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=71

以上接口是不能直接进行访问的,需要在请求的时候加上Referer,下面以《今日热门视频》数据为例


今日热门视频

已知今日热门视频的数据接口 和请求方式,可以直接使用requests进行请求。
代码非常简单,请求其他的接口只需要更换 url 即可。

import requests

hot_video_url = 'https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=4'

headers = {
           "user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36",
           "referer": "https://creator.douyin.com/billboard/hot_aweme"
           }

response = requests.get(url=hot_video_url, headers=headers).json()

print(response)

返回数据示例:
在这里插入图片描述


获取视频详情

在返回过来的数据中,可以看到并没有视频的详细内容,
只有作者名auhor,视频背景图 img_url,分享页链接link,排名rank,标题title,热度value

当想要获得更多的视频信息,比如点赞、转发、评论 或者是 作者的信息,就需要通过其他接口来获取数据。

这里随便选择了一个分享链接Link:
https://www.iesdouyin.com/share/video/6844023242781412622/?region=CN&mid=6844023258854345479&u_code=0&titleType=title
在这里插入图片描述
通过抓包发现了数据的接口:
https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=6844023242781412622

(该接口可直接访问。只有一个 item_ids 参数,可以发现该item_ids和分享链接上video后面的id相同 )

返回数据如下:
在这里插入图片描述


代码示例

先获取《今日热门视频》集合,然后提取出每一个视频对应的item_ids,再根据id获取详细的视频数据

# -*- coding: utf-8 -*-

import requests
import re

hot_video_url = 'https://creator.douyin.com/aweme/v1/creator/data/billboard/?billboard_type=4'

headers = {
           "user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36",
           "referer": "https://creator.douyin.com/billboard/hot_aweme"
           }

response = requests.get(url=hot_video_url, headers=headers).json()


for video in response['billboard_data']:
    link = video['link']            # 分享页链接
    title = video['title']          # 视频标题
    rank = (video['rank'])          # 当前排名
    hot_value = video['value']      # 当前热度

    items_ids = re.findall('video/(.*?)/', link)[0]    # 获取详情数据需要的id

    video_detail_url = 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={}'.format(items_ids)

    detail = requests.get(video_detail_url,headers=headers).json()

    print(detail['item_list'][0]['share_url'])

    break   # 只取1条,示例

本文地址:https://blog.csdn.net/weixin_43582101/article/details/107082121

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网