zoukankan      html  css  js  c++  java
  • Python爬取抖音视频

    最近在研究Python爬虫,顺便爬了一下抖音上的视频,找到了哥们喜欢的小姐姐居多,咱们给他爬下来吧.

    最终爬取结果

     好了废话补多说了,上代码!

     1 #https://www.iesdouyin.com/aweme/v1/aweme/favorite/?user_id=86371592618
     2 #&count=21&max_cursor=0&aid=1128&_signature=fBZqMxAcIH.WOSqz4s5eTHwWai&dytk=6849c66ff2a629554679fe#e4ad1343a5
     3 #分析url https://www.iesdouyin.com/share/user/86371592618
     4 #最终获取用户喜欢
     5 import requests
     6 
     7 url="https://www.iesdouyin.com/share/user/86371592618"
     8 #抖音本身反爬虫措施
     9 headers={
    10     'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
    11 }
    12 #获得dytk
    13 reponse=requests.get(url,headers=headers)
    14 reponse.encoding='utf-8'
    15 #print(reponse.text)
    16 #获得dytk 通过正则进行筛选
    17 import re
    18 dytk=re.search("dytk: '(.*?)'",reponse.text).group(1)
    19 print(dytk)
    20 
    21 #组装数据
    22 params={
    23     'user_id':'86371592618',
    24     'count':'21',
    25     'max_cursor': '0',
    26     'aid': '1128',
    27     'dytk': dytk
    28 }
    29 
    30 aweme_list=[]
    31 def get_favor_video():
    32     #引用全局变量
    33     global aweme_list
    34     while True:
    35         # 请求数据
    36         furl = "https://www.iesdouyin.com/aweme/v1/aweme/favorite/"
    37         jsonstr = requests.get(furl, params=params, headers=headers).json()
    38         print(jsonstr)
    39         # 多次请求会出现正确数据
    40         #修改全局变量的值
    41         aweme_list = jsonstr.get('aweme_list')
    42         print(aweme_list)
    43         if len(aweme_list)!=0:
    44             break
    45 
    46 get_favor_video()
    47 
    48 #进行下一步解析
    49 #拼接视频地址
    50 for item in aweme_list:
    51     #读取视频uri
    52     video_uri=item['video']['play_addr']['uri']
    53     #拼接视频地址
    54     video="https://aweme.snssdk.com/aweme/v1/playwm/?video_id="+video_uri
    55     #下载视频
    56     #读取视频名称
    57     title=item['share_info']['share_desc']
    58     #写入视频
    59     mp4=requests.get(video,headers=headers,stream=True).content
    60     open('F:/PythonWork/test/video/' + title+'.mp4', 'wb').write(mp4)
    61 print("下载完成")

    个人博客地址  http://zweice.com   喜欢的支持下了~

  • 相关阅读:
    网易企业免费邮箱
    168. Excel Sheet Column Title
    167.Two Sum II-Input array is sorted
    166. Fraction to Recurring Decimal
    165 Compare Version Numbers
    164. Maximum Gap
    163.Missing Ranges
    162.Find Peak Element
    161.One Edit Distance
    160. Intersection of Two Linked Lists
  • 原文地址:https://www.cnblogs.com/mrccjj/p/10405204.html
Copyright © 2011-2022 走看看