抖音爬蟲

import requests import time import re import json import pandas as pd headers= {'user-agent': 'mobile'} def douyin_Spyder(id,url2): data=requests.get('http://aweme.snssdk.com/aweme/v1/user/?user_id={}&retry_type=retry_http&iid=59238161664&device_id=62578609382&ac=wifi&channel=aweGW&aid=1128&app_name=aweme&version_code=230&version_name=2.3.0&device_platform=android&ssmix=a&device_type=CHM-TL00H&device_brand=Honor&language=zh&os_api=19&os_version=4.4.4&uuid=745270478576539&openudid=589e358ee90e53&manifest_version_code=230&resolution=720*1280&dpi=320&update_version_code=2302&_rticket=1548395034447&ts={}&as=a1659a843a314c425a4355&cp=a518ca55a1a04624e1gkoo&mas=0141e7dcb9b69675674bffb55a194f1c3facaccc2c86ac4c2cc62c'.format(id,time.time()),headers=headers) data2 = requests.get(url2,headers=headers) data2=requests.get(url2,headers=headers) content=data.content.decode('utf-8') dict_json = json.loads(content) print('******主頁數據******') print('粉絲數:',dict_json['user']['follower_count']) print('獲贊數:', dict_json['user']['total_favorited']) content2 = data2.content.decode('utf-8') dict_json2 = json.loads(content2) aweme_list=dict_json2['aweme_list'] print('******視頻區數據******') comment_count_list=[] digg_count_list = [] share_count_list = [] play_list = [] forward_count_list = [] id=[] desc=[] for i,key  in enumerate(aweme_list): # print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
        # print('標題:',key['desc'])
        # print('ID:',key['aweme_id'])
        video=key['video']['play_addr']['url_list'][1] print('視頻地址:',key['video']['play_addr']['url_list'][1]) res = requests.get(video, headers=headers) with open(r'C:/Users/Administrator/Desktop/B站視頻/迪麗熱巴'+str(i)+'.mp4', 'wb') as f: f.write(res.content) # print('分享地址:',key['share_url'])
        # print('評論數:',key['statistics']['comment_count'])
        # print('點贊數:', key['statistics']['digg_count'])
        # print('轉發量:', key['statistics']['share_count'])
        # print('forward_count:', key['statistics']['forward_count'])
        comment_count_list .append(key['statistics']['comment_count']) digg_count_list.append(key['statistics']['digg_count']) share_count_list .append(key['statistics']['share_count']) forward_count_list.append( key['statistics']['forward_count']) play_list.append(key['share_url']) id.append(key['aweme_id']) desc.append(key['desc']) df = pd.DataFrame({'ID': id, '標題': desc,'連接地址':play_list,'評論數':comment_count_list,'點贊數':digg_count_list,'轉發量':share_count_list}) df=df.set_index('ID') tim=time.strftime('%Y-%m-%d',time.localtime(time.time())) df.to_excel('C:/Users/Administrator/Desktop/'+str(tim)+'-7.xlsx') if __name__ == '__main__': url2=input('url:') douyin_Spyder(79302973596,url2)
相關文章
相關標籤/搜索