爬虫案列 --抖音视频批量爬取

2024-01-05 11:04

本文主要是介绍爬虫案列 --抖音视频批量爬取,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

"""
====================================================================项目名称: 唯品会商品数据爬取
项目描述: 通过requests框架获取网页数据
项目环境: pycharm && python3.8
作者所属: 几许====================================================================1. 对主页抓包 , 鼠标移动到视频位置视频自动播放获得视频数据包
2. 对视频数据包地址进行解析 , 复制链接 , 进行检索
3. 获得视频的数据表
4. 转化为字典类型 , 通过取值获得相应数据===================================================================="""import requests
import json
import os
from tqdm import tqdmclass Spider():def __init__(self):self.name = input("用户名称:")self.url = 'https://www.douyin.com/aweme/v1/web/aweme/post/?device_plat' \'form=webapp&aid=6383&channel=channel_pc_web&sec_user_id=MS4wLj' \'ABAAAARSI_YyerRex7gC78FWY-wnL9LA0VLV0-hw4MsHQXKQc&max_cursor=0&' \'locate_item_id=7319002747116719394&locate_query=false&show_live_' \'replay_strategy=1&need_time_list=1&time_list_query=0&whale_cut_t' \'oken=&cut_version=1&count=18&publish_video_strategy_type=2&pc_cli' \'ent_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=tr' \'ue&screen_width=1739&screen_height=1087&browser_language=zh-CN&browser' \'_platform=Win32&browser_name=Chrome&browser_version=120.0.0.0&browser' \'_online=true&engine_name=Blink&engine_version=120.0.0.0&os_name=Windo' \'ws&os_version=10&cpu_core_num=16&device_memory=8&platform=PC&downlink' \'=10&effective_type=4g&round_trip_time=50&webid=7317298922984064552&ms' \'Token=41miuagnXWbrfJA3fKZcTLpK0uZqsPeVIPFNrcpnIa_qqykpK8IUO85mYnyTrEK' \'grcP_ZMaiDJQmc_yPjtSsGWaRtHX9RUkMff5DWnIlxahYCAHBDBD4wC1IuDBE1Q==&X-Bo' \'gus=DFSzswVObKiANy5nt74z2vB9PimP'self.headers = {'authority': 'www.douyin.com','accept': 'application/json, text/plain, */*','accept-language': 'zh-CN,zh;q=0.9','cookie': 'ttwid=1%7CetvXY3q8LycHG8S_Jbdkn0coDJBB1g4jDT8rUsZxkgE%7C1703691433%7C25a10db3f3cb2286bc61c5df891762b53ed86642718f6514a971a1dd5b926b60; dy_swidth=1739; dy_sheight=1087; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Atrue%2C%22volume%22%3A0.6%7D; s_v_web_id=verify_lqnxw3p8_LHhIVuoi_xT4U_4GAO_Bso3_NXXogcEL5P6L; passport_csrf_token=a400b27cd87ff688e2ed491b78c86cec; passport_csrf_token_default=a400b27cd87ff688e2ed491b78c86cec; xgplayer_user_id=85464987351; bd_ticket_guard_client_web_domain=2; ttcid=982e11696ecb4394a427ca8a8bc61b8712; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%2C%22isForcePopClose%22%3A1%7D; passport_assist_user=CkGdWr_4NXuB6776SugOMjnvz8kqR8AAMU-Oo472dCf56_f5plVV3JVgBZS9xHMtKkUpDNjW4YE-wNMhS2l7KCGLaBpKCjy7KERoTX9NxbrlQ4fwf80IWklA7yrQ68hpu4tGNpmPPb5DgZY1oISMsOHOHsdhCZyB4S2tzcky5UgdolAQ-b_FDRiJr9ZUIAEiAQMCSFAU; n_mh=aOe6MoW0EhRYuUYuxK7zU5ABLi2JtbyKLjBKJVaPHY4; sso_uid_tt=6ed47ea04759b3a853fbad85bf16f1c0; sso_uid_tt_ss=6ed47ea04759b3a853fbad85bf16f1c0; toutiao_sso_user=be81bb8ea7faacdcbc9dd5db7758dcde; toutiao_sso_user_ss=be81bb8ea7faacdcbc9dd5db7758dcde; sid_ucp_sso_v1=1.0.0-KDExYWI4ZTY3MzIwZDMxOTFkZmZiNDY1NTE4ODMzOGI4OTM4MTJmODYKHwi9tIDt1YzkAxChhMusBhjvMSAMMMDC14IGOAZA9AcaAmxmIiBiZTgxYmI4ZWE3ZmFhY2RjYmM5ZGQ1ZGI3NzU4ZGNkZQ; ssid_ucp_sso_v1=1.0.0-KDExYWI4ZTY3MzIwZDMxOTFkZmZiNDY1NTE4ODMzOGI4OTM4MTJmODYKHwi9tIDt1YzkAxChhMusBhjvMSAMMMDC14IGOAZA9AcaAmxmIiBiZTgxYmI4ZWE3ZmFhY2RjYmM5ZGQ1ZGI3NzU4ZGNkZQ; passport_auth_status=66f3029dfff0bfcbcc4a88214c47101a%2C; passport_auth_status_ss=66f3029dfff0bfcbcc4a88214c47101a%2C; uid_tt=30af4edf2be0abcf7863968a5619085f; uid_tt_ss=30af4edf2be0abcf7863968a5619085f; sid_tt=2876f1470127b791f0cf9a72cd86dfe8; sessionid=2876f1470127b791f0cf9a72cd86dfe8; sessionid_ss=2876f1470127b791f0cf9a72cd86dfe8; publish_badge_show_info=%220%2C0%2C0%2C1704116788119%22; LOGIN_STATUS=1; _bd_ticket_crypt_doamin=2; _bd_ticket_crypt_cookie=e7315ef4e091ee513451063fa2da5513; __security_server_data_status=1; sid_guard=2876f1470127b791f0cf9a72cd86dfe8%7C1704116794%7C5183978%7CFri%2C+01-Mar-2024+13%3A46%3A12+GMT; sid_ucp_v1=1.0.0-KDhiOTQ5YTE0NDA1ZmJjMWViOWZmNmZmZjFmNTc5NTA2MTU1MGM1OWUKGwi9tIDt1YzkAxC6hMusBhjvMSAMOAZA9AdIBBoCbGYiIDI4NzZmMTQ3MDEyN2I3OTFmMGNmOWE3MmNkODZkZmU4; ssid_ucp_v1=1.0.0-KDhiOTQ5YTE0NDA1ZmJjMWViOWZmNmZmZjFmNTc5NTA2MTU1MGM1OWUKGwi9tIDt1YzkAxC6hMusBhjvMSAMOAZA9AdIBBoCbGYiIDI4NzZmMTQ3MDEyN2I3OTFmMGNmOWE3MmNkODZkZmU4; store-region=cn-ah; store-region-src=uid; download_guide=%223%2F20240101%2F1%22; my_rd=2; EnhanceDownloadGuide=%220_0_0_0_1_1704117357%22; pwa2=%220%7C0%7C3%7C0%22; strategyABtestKey=%221704267225.226%22; SEARCH_RESULT_LIST_TYPE=%22single%22; douyin.com; device_web_cpu_core=16; device_web_memory_size=8; architecture=amd64; csrf_session_id=3af6123a976801945da40296beb67c81; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1739%2C%5C%22screen_height%5C%22%3A1087%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A16%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A50%7D%22; __ac_nonce=06595391400381d9d7250; __ac_signature=_02B4Z6wo00f01kfyV6wAAIDBeltNM7xgII5H0lMAAPR4zvgmgRl4bZQiw8Hy7m1HJQyGxv-69JHZ7ep7bv06SKWB3HnU902JGVt5BoxWU57grcNKrgwl0D1h-fnclHqOBW1bw14QCmbhuaeCea; FOLLOW_NUMBER_YELLOW_POINT_INFO=%22MS4wLjABAAAAH_la9atp1nq0NfBl06KGYylxI45qL-L_V1YPgFrYa2a44J05vyu0abQGp13pO8_m%2F1704297600000%2F1704267233660%2F0%2F1704279492177%22; tt_scid=jaahDcXkVC9dvqUIH5uGmlzxfBiNsOFnKCsQFb1O8AspLavoMj5sv3PBOnnmhNLAd099; passport_fe_beating_status=true; stream_player_status_params=%22%7B%5C%22is_auto_play%5C%22%3A0%2C%5C%22is_full_screen%5C%22%3A0%2C%5C%22is_full_webscreen%5C%22%3A0%2C%5C%22is_mute%5C%22%3A1%2C%5C%22is_speed%5C%22%3A1%2C%5C%22is_visible%5C%22%3A0%7D%22; xg_device_score=7.664966583511937; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCUGltTkFHc1RpTkhpNmNyeFhOSExXb2tMQ3duQWE2RnQyNGZNSlVnbVVlOTBzQ3NSUGpqVSt2ajVjUUl0czBtOEFBNGl4K1Y2MWRTOHorTGVnY2FBeE09IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D; msToken=tyKrHlga8UZGJDBEwpGp7urIvXmrT9jeFWRj35PdBv6_f1bvA1RrKwQKipwekauBXqeeSDLP3tyH32ow7LFDhA50p8N1dAmoMScRT-2JNrl0wQ4HW-jGM_-imzkb; msToken=F4m6s_dH7A-07AFYB0Xd0TvUzrjRVYE6ZHvFsVzD8h3O6IU_0foQiXoFw0zFG1D1alVcOEsFgU0NbraMql0b3JAZX7EWmsvhkNPem0iik9HWek_CFpw2lY8kS9gX; odin_tt=3ecfdb9d2b86cb25ea7999936d0bac85c7423d8abe2fcab0ac0b4e89a71be53a73c178c90455d05d6454792b4a4d822d90ec2afdfb6edd932ca068a1cb79e012; IsDouyinActive=true; home_can_add_dy_2_desktop=%220%22','referer': 'https://www.douyin.com/user/MS4wLjABAAAAkzRSrOuSsM4Z1Ricsddumx_aSvX0jmOPcQR2qTs3PEtImBD8BomLrqvtIOBKOL0P','sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"','sec-ch-ua-mobile': '?0','sec-ch-ua-platform': '"Windows"','sec-fetch-dest': 'empty','sec-fetch-mode': 'cors','sec-fetch-site': 'same-origin','user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'        }def prase_data(self):msg = requests.get(self.url, headers=self.headers).textjson_msg = json.loads(msg)dict_msg = json_msg['aweme_list']for dict in tqdm(dict_msg):if dict['desc'] == '':title = dict['aweme_id']elif dict['desc'].split()[0]:title = dict['desc'].split()[0]else:title = dict['desc']link = dict['video']['play_addr']['url_list'][0]if title == '':title = dict['aweme_id']movie = requests.get(link).contentself.keep_data(title,movie)def keep_data(self,title,link):if not os.path.exists(self.name):os.makedirs(self.name)with open(f'{self.name}\{title}.mp4','wb')as f:f.write(link)if __name__ == '__main__':spider = Spider()spider.prase_data()

这篇关于爬虫案列 --抖音视频批量爬取的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/572651

相关文章

使用Python制作一个PDF批量加密工具

《使用Python制作一个PDF批量加密工具》PDF批量加密‌是一种保护PDF文件安全性的方法,通过为多个PDF文件设置相同的密码,防止未经授权的用户访问这些文件,下面我们来看看如何使用Python制... 目录1.简介2.运行效果3.相关源码1.简介一个python写的PDF批量加密工具。PDF批量加密

通过C#和RTSPClient实现简易音视频解码功能

《通过C#和RTSPClient实现简易音视频解码功能》在多媒体应用中,实时传输协议(RTSP)用于流媒体服务,特别是音视频监控系统,通过C#和RTSPClient库,可以轻松实现简易的音视... 目录前言正文关键特性解决方案实现步骤示例代码总结最后前言在多媒体应用中,实时传输协议(RTSP)用于流媒体服

Python按条件批量删除TXT文件行工具

《Python按条件批量删除TXT文件行工具》这篇文章主要为大家详细介绍了Python如何实现按条件批量删除TXT文件中行的工具,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1.简介2.运行效果3.相关源码1.简介一个由python编写android的可根据TXT文件按条件批

Java实现批量化操作Excel文件的示例代码

《Java实现批量化操作Excel文件的示例代码》在操作Excel的场景中,通常会有一些针对Excel的批量操作,这篇文章主要为大家详细介绍了如何使用GcExcel实现批量化操作Excel,感兴趣的可... 目录前言 | 问题背景什么是GcExcel场景1 批量导入Excel文件,并读取特定区域的数据场景2

Python3 BeautifulSoup爬虫 POJ自动提交

POJ 提交代码采用Base64加密方式 import http.cookiejarimport loggingimport urllib.parseimport urllib.requestimport base64from bs4 import BeautifulSoupfrom submitcode import SubmitCodeclass SubmitPoj():de

音视频入门基础:WAV专题(10)——FFmpeg源码中计算WAV音频文件每个packet的pts、dts的实现

一、引言 从文章《音视频入门基础:WAV专题(6)——通过FFprobe显示WAV音频文件每个数据包的信息》中我们可以知道,通过FFprobe命令可以打印WAV音频文件每个packet(也称为数据包或多媒体包)的信息,这些信息包含该packet的pts、dts: 打印出来的“pts”实际是AVPacket结构体中的成员变量pts,是以AVStream->time_base为单位的显

Python:豆瓣电影商业数据分析-爬取全数据【附带爬虫豆瓣,数据处理过程,数据分析,可视化,以及完整PPT报告】

**爬取豆瓣电影信息,分析近年电影行业的发展情况** 本文是完整的数据分析展现,代码有完整版,包含豆瓣电影爬取的具体方式【附带爬虫豆瓣,数据处理过程,数据分析,可视化,以及完整PPT报告】   最近MBA在学习《商业数据分析》,大实训作业给了数据要进行数据分析,所以先拿豆瓣电影练练手,网络上爬取豆瓣电影TOP250较多,但对于豆瓣电影全数据的爬取教程很少,所以我自己做一版。 目

Python脚本:对文件进行批量重命名

字符替换:批量对文件名中指定字符进行替换添加前缀:批量向原文件名添加前缀添加后缀:批量向原文件名添加后缀 import osdef Rename_CharReplace():#对文件名中某字符进行替换(已完结)re_dir = os.getcwd()re_list = os.listdir(re_dir)original_char = input('请输入你要替换的字符:')replace_ch

Python脚本:批量解压RAR文件

所需模块: os.getcwd() #获取脚本文件路径os.system() #执行系统命令 import os#source_dir = input("Please input in source_dir:")#unzip_dir = input("Please input in unzip_dir:") source_dir = os.

vcpkg子包路径批量获取

获取vcpkg 子包的路径,并拼接为set(CMAKE_PREFIX_PATH “拼接路径” ) import osdef find_directories_with_subdirs(root_dir):# 构建根目录下的 "packages" 文件夹路径root_packages_dir = os.path.join(root_dir, "packages")# 如果 "packages"