Python3之抖音无水印视频解析脚本

因为服务器太渣,链接就不放出来了。记住返回的这个数据结构就可以了!

#在抖音,记录美好生活#智商不在线的一瞬间 http://v.douyin.com/U3a3QD/ 复制此链接,打开【抖音短视频】,直接观看视频!
# 短链接最后的斜杠不要添加上
short_url = "http://v.douyin.com/U3a3QD"
parse_url = "http://www.xxx.cn/parseByLink.php?url=%s" % short_url
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36"
}


def send_request():
    rs = requests.session()
    retval = rs.get(parse_url, headers=headers).text
    retval = json.loads(retval)
    # print(retval)
    return retval


flag = True
video_url = ""
video_title = ""
while flag:
    ret = send_request()
    time.sleep(random.randint(5, 10))
    if not ret['status']:
        print(ret)
    else:
        flag = False
        video = ret['data']['urls'][0]
        title = ret['data']['info']["share_title"]
        # print(video)
        print(title)
        if not ret['data']['long_video']:
            video_url = video
        else:
            video_url = ret['data']['long_video']
        video_title = title
# 处理视频数据
headers = {
    "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/15.0b13894 Mobile/16D57 Safari/605.1.15"
}
ret = requests.get(video_url, headers=headers).content
with open("%s.mp4" % video_title, 'wb') as f:
    f.write(ret)

你可能感兴趣的:(爬虫)