码迷,mamicode.com
首页 > 其他好文 > 详细

批量下载抖音某用户的所有作品

时间:2021-03-02 11:50:01      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:packages   mac   app   find   shared   lun   esc   version   als   

import requests
import re
import os
from glom import *

def get_video(url):
    requests.packages.urllib3.disable_warnings()
    session = requests.session()

    headers = {User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1}
    res = session.get(url=url, headers=headers, verify=False)
    seu_udi = re.findall(rsec_uid=(\w+-\w+-\w+|\w+-\w+|\w+), res.url)

    sum_url = https://www.iesdouyin.com/web/api/v2/user/info/?sec_uid={0}.format(seu_udi[0])
    se = session.get(sum_url).json()
    video_count = glom(se, user_info.aweme_count)
    nickname = glom(se, user_info.nickname)
    short_id = glom(se, user_info.short_id)
    print("nickname:%s" % nickname)
    print("video_count:%s" % video_count)
    with open(f{short_id}-{nickname}.txt, wt) as f:
        f.write("nickname: "+nickname+"\n")
        f.write("short_id: "+short_id+"\n")

    max_cursor = 0
    id = 0
    w2 = 0
    while True:
        while True:
            if (max_cursor == 0):
                sec_id_url = "https://www.iesdouyin.com/web/api/v2/aweme/post/?sec_uid={0}&count=21&max_cursor=0&aid=1128&_signature=dF8skQAAK0iTKNSXi9av.XRfLI&dytk=".format(
                    seu_udi[0])
            else:
                sec_id_url = "https://www.iesdouyin.com/web/api/v2/aweme/post/?sec_uid={0}&count=21&max_cursor={1}&aid=1128&_signature=dF8skQAAK0iTKNSXi9av.XRfLI&dytk=".format(
                    seu_udi[0], max_cursor)
            sec_respone = session.get(url=sec_id_url, headers=headers, verify=False)
            comment = sec_respone.json()
            if (len(comment[aweme_list]) == 0):
                w2 += 1
                if w2 >= 1:
                    break 
                continue
            else:
                break
max_cursor = comment[max_cursor] for s in comment[aweme_list]: id += 1 desc = s[desc] text = s[aweme_id] dianzan = s[statistics]["digg_count"] pinglun = s[statistics]["comment_count"] fenxiang = s[statistics]["share_count"] video_url = s[video][play_addr_lowbr][url_list][0] with open(f{short_id}-{nickname}.txt, a) as f: f.write(str(dianzan)+","+str(fenxiang)+","+video_url+"\n") print(str(id) +"/"+ str(video_count) + ",{0},点赞:{1},评论:{2},分享:{3} {4}".format(text, str(dianzan), str(pinglun),str(fenxiang), desc)) est = requests.get(url=video_url, headers=headers) if not os.path.exists(short_id+‘-‘+nickname): os.mkdir(short_id+‘-‘+nickname) with open(f‘{short_id}-{nickname}/{dianzan}-{text}.mp4‘, ‘wb‘) as f: f.write(est.content) if(int(id) >= int(video_count)): break if __name__ == __main__: url = input("input shared url:") get_video(url)

 

批量下载抖音某用户的所有作品

标签:packages   mac   app   find   shared   lun   esc   version   als   

原文地址:https://www.cnblogs.com/nlsoft/p/14461441.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!