import requests
import os
head = {
# 'Cookie': 'did=web_fcc06fb2a98a2cff056e960853ad3d5c; didv=1702555181874; _bl_uid=qhlnaqUC5wy52Fe7taUzgts3tLyL; kpf=PC_WEB; clientid=3; userId=1235119487; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABRBYHQz9c1-dI8jJk7R-3Wh_-p5_zmRIOU_dWB9J_ySmk8UW8ZFMvlRHJpjx1zw4_cFIt5raupDauvOxxMzittdNIJmijnuEbwq7Pl_tqQMOwPci8p8-f4Xla9VWreCpsplBmHkSENZR5dLVMeB4KtcBsPeKfiDod72zd0Bmc1SZLikr7OTVMp1rQykg2OvAwfgIe5FN_lyBlOGlnP8CFlxoS6NMArymx9EWAk7l-bjDNUah-IiDvsnkEip4HnBktU13kizAReg-7sd4PLHcg19_gMrPcDigFMAE; kuaishou.server.web_ph=c856b7dff1b5df35201de165c1cace8d1efd; kpn=KUAISHOU_VISION',
'Cookie': 'did=web_fcc06fb2a98a2cff056e960853ad3d5c; didv=1702555181874; _bl_uid=qhlnaqUC5wy52Fe7taUzgts3tLyL; kpf=PC_WEB; clientid=3; userId=1235119487; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqAB7ScIomu26TVO1-WlSDNe4oEza9RD2F1iYpKN3Y7ivu-ZWV59j_n9TdDjmJSYlg2JwU8I9sSTr4gQs-5YP_Mw1f3fcl_F_1t2iKwIrEPo0J_a9n33d4gfNKK_xe3WKbKPQKuz7enocpPJ1fpbhMa34CkPXXPGBPC2uD9YeSO_HSUzmOFSfo9Xl-DtDOIEAo-cSQvZlIf4KmAlgPuzbwypuxoS-1Rj5-IBBNoxoIePYcxZFs4oIiD3NdIrH6WgwyDJhZjVD1d4G0rZi3ivG7dSwZ7ezhKWpSgFMAE; kuaishou.server.web_ph=bb99be98cf4a1a35c78e9a5c317b542a1241; kpn=KUAISHOU_VISION',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
url = 'https://www.kuaishou.com/graphql'
cur = ''
global num
num = 1
isNotExit = True
userID = input( '请输入需要下载的快手ID号:' )
while isNotExit:
data = {"operationName": "visionProfilePhotoList",
"variables": {"userId": userID, "pcursor": cur, "page": "detail", "webPageArea": "profilexxnull"},
"query": "fragment photoContent on PhotoEntity {\n __typename\n id\n duration\n caption\n originCaption\n likeCount\n viewCount\n commentCount\n realLikeCount\n coverUrl\n photoUrl\n photoH265Url\n manifest\n manifestH265\n videoResource\n coverUrls {\n url\n __typename\n }\n timestamp\n expTag\n animatedCoverUrl\n distance\n videoRatio\n liked\n stereoType\n profileUserTopPhoto\n musicBlocked\n}\n\nfragment recoPhotoFragment on recoPhotoEntity {\n __typename\n id\n duration\n caption\n originCaption\n likeCount\n viewCount\n commentCount\n realLikeCount\n coverUrl\n photoUrl\n photoH265Url\n manifest\n manifestH265\n videoResource\n coverUrls {\n url\n __typename\n }\n timestamp\n expTag\n animatedCoverUrl\n distance\n videoRatio\n liked\n stereoType\n profileUserTopPhoto\n musicBlocked\n}\n\nfragment feedContent on Feed {\n type\n author {\n id\n name\n headerUrl\n following\n headerUrls {\n url\n __typename\n }\n __typename\n }\n photo {\n ...photoContent\n ...recoPhotoFragment\n __typename\n }\n canAddComment\n llsid\n status\n currentPcursor\n tags {\n type\n name\n __typename\n }\n __typename\n}\n\nquery visionProfilePhotoList($pcursor: String, $userId: String, $page: String, $webPageArea: String) {\n visionProfilePhotoList(pcursor: $pcursor, userId: $userId, page: $page, webPageArea: $webPageArea) {\n result\n llsid\n webPageArea\n feeds {\n ...feedContent\n __typename\n }\n hostName\n pcursor\n __typename\n }\n}\n"}
response = requests.post( url=url, headers=head, json=data )
json_data = response.json()
cur = json_data['data']['visionProfilePhotoList']['pcursor']
if cur == 'no_more':
isNotExit = False
video_firstPage_datas = json_data['data']['visionProfilePhotoList']['feeds']
file_folder_name = video_firstPage_datas[0]['author']['name']
path = "视频/"
# homedir = os.getcwd() # 获取项目当前路径
folder_name = f'{file_folder_name}'
if os.path.exists(path+folder_name):
pass
else:
os.mkdir( os.path.join( path, folder_name ) )
for video_one_data in video_firstPage_datas:
url_video = video_one_data['photo']['photoH265Url']
if url_video == '':
url_video = video_one_data['photo']['photoUrl']
one_video_response = requests.get( url=url_video, headers=head )
with open( f'视频/{folder_name}/{num}.mp4', 'wb' ) as f:
f.write( one_video_response.content )
print( f'已经下载了第{num}个视频' )
num += 1
if num > 25:
print( '已经下载25个视频,够了够了!!!' )
isNotExit = False
break
使用python批量爬取某手视频
最新推荐文章于 2024-07-26 00:35:17 发布