抖音根据关键词,点赞量,下载视频第一次写,不知道怎么写直接发作品吧
[Python] 纯文本查看 复制代码 import json
import os
import re
import time
import requests
import urllib.parse
# offset 好像是解决翻页的
nn = 1
sun_s = 0
gjc_name=input("输入关键词")
max_bofangliang= int(input('点赞量'))
key = urllib.parse.quote(gjc_name)
# print(key)
while True:
url = f'https://www.douyin.com/aweme/v1/web/general/search/single/?device_platform=webapp&aid=6383&channel=channel_pc_web&search_channel=aweme_general&sort_type=0&publish_time=0&keyword={key}&search_source=normal_search&query_correct_type=1&is_filter_search=0&from_group_id=&offset={sun_s * 10}&count=10&search_id=202209151332480101402051633D0E8650&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=2560&screen_height=1080&browser_language=zh-CN&browser_platform=Win32&browser_name=Chrome&browser_version=105.0.0.0&browser_online=true&engine_name=Blink&engine_version=105.0.0.0&os_name=Windows&os_version=10&cpu_core_num=12&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=100&webid=7129806389195458082&msToken=20jBGIfrrkKSgtlRmqkkoaFZIj-hQEwWI2LVMn4kASh_Jg_VAJCVGW9q5gwmCLXQnEFn8KdqlEJxrjF7geVghbpbUDCgZS5GJhVjGsTSrXE382FG5H-sKFM=&X-Bogus=DFSzswVLF50ANydASsRgAKXAIQ-S'
headers = {
"Cookie": "",#登录后输入自己的Cookie
"referer": "https://www.douyin.com/search/%E5%84%BF%E5%AD%90?aid=165d20aa-17b3-4b63-b831-645b2eb7f064&publish_time=0&sort_type=0&source=normal_search&type=general",
"User-Agent": "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
}
#
resp = requests.get(url, headers=headers)
# print(resp.text)
# resp.encoding='urf-8'
respss = json.loads(resp.text)
# print(respss)
# print(respss)
for i in respss['data'][:-1]:
try:
url = i['aweme_info']['video']['play_addr']['url_list'][0]
name = i['aweme_info']['desc']
aweme_id = i['aweme_info']['aweme_id']
# print(aweme_id)
# print(i['aweme_info']['video']['play_addr']['url_list'][0])
bofangliang = i['aweme_info']['statistics']['digg_count']
if bofangliang > max_bofangliang and gjc_name in name :
if not os.path.exists(f'./{gjc_name}'): # 如果作者文件夹不存在,就创建
os.mkdir(f'./{gjc_name}') # 如果作者文件夹不存在,就创建一个
video_name = name # 获取视频名称
video_name = video_name.replace('\n', ' ') # 吧\n替换成空格
video_name = re.sub(r'[\/:*?"<>|]', '-', video_name) # 替换文件名中的特殊字符
resp = requests.get(url)
file_object = open(f'./{gjc_name}/{bofangliang}_{video_name}.mp4', mode='wb')
file_object.write(resp.content)
file_object.close()
print(f'第{nn}个视拼,名称:{bofangliang}_{video_name}')
nn += 1
except:
pass
time.sleep(5)
sun_s += 1
print(sun_s)
|