鍓嶈█
鍡ㄥ柦~澶у濂藉憖锛岃繖閲屾槸榄旂帇鍛?鉂?~!
鍒峰埌鐨勮棰戞€曞畠涓嬫灦锛熸垜浠潵閲囬泦淇濆瓨涓€涓嬪畠
鐭ヨ瘑鐐?
鍔ㄦ€佹暟鎹姄鍖?/p>
requests鍙戦€佽姹?/p>
json鏁版嵁瑙f瀽
寮€鍙戠幆澧?
python 3.8 杩愯浠g爜
pycharm 2022.3 杈呭姪鏁蹭唬鐮?/p>
requests pip install requests
浠g爜灞曠ず
瀵煎叆妯″潡
import re
import requests # 鍙戦€佽姹?
浼
headers = {
'Cookie': 'kpf=PC_WEB; clientid=3; did=web_4bf90ac4df8aaef2d99527f1da1063fd; userId=3075864129; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqAB9tSqSgbeN3Qhc4H_V6Awn1-yfEnaceVEJQUhtxgCBBHHQl_DyWKPYDO3XIdjFQTHwSSFOPZL6FPTk7LSW1dfp7qvBSeP4ANjPT1evIoq9ODcPJyb6YgEIdsV-Dzm_Sq73yQg6jYhvuRNJGwAM_GfAfUKWiG4RDdGDpHd1uCAJd0qM2xZwqzr11JlIz3yRFeNFNfO2zINkJAktY8lUyQwuRoS9XMBYg26NCtIxdOwhbHEY-u6IiBNGgmRMQXPmCodWM1RM7oFpjHSgD61betJSR00w0VYtSgFMAE; kuaishou.server.web_ph=69e54c87baac46f523262858017c7988cf22; kpn=KUAISHOU_VISION',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'
}
璇锋眰閾炬帴
url = 'https://www.****.com/graphql'
pcursor = ""
while True:
# 璇锋眰浣?
json = {
'operationName': "visionProfilePhotoList",
'query': "fragment photoContent on PhotoEntity {\n id\n duration\n caption\n originCaption\n likeCount\n viewCount\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 __typename\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 __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",
'variables': {'userId': "3xjfq9eesf4kxwg", 'pcursor': pcursor, 'page': "profile"}
}
- 鍙戦€佽姹?/li>
response = requests.post(url=url, headers=headers, json=json)
- 鑾峰彇鏁版嵁
json_data = response.json()
- 瑙f瀽鏁版嵁
閿? 鍊?閫氳繃:鍓嶉潰鐨勫唴瀹?鍙?鍚庨潰鐨勫唴瀹?/p>
feeds = json_data['data']['visionProfilePhotoList']['feeds']
pcursor = json_data['data']['visionProfilePhotoList']['pcursor']
for feed in feeds:
photoUrl = feed['photo']['photoUrl']
caption = feed['photo']['caption']
caption = re.sub('[\\/:*?"<>|]', '', caption)
print(caption, photoUrl)
- 淇濆瓨鏁版嵁
video_data = requests.get(photoUrl).content
with open(rf"C:\Users\Administrator\Desktop\video\{caption}.mp4", mode='wb') as f:
f.write(video_data)
if pcursor == "no_more":
break
鏁堟灉灞曠ず
灏捐 馃挐
瑕佹垚鍔燂紝鍏堝彂鐤紝涓嬪畾鍐冲績寰€鍓嶅啿锛?/p>
瀛︿範鏄渶瑕侀暱鏈熷潥鎸佺殑锛屼竴姝ヤ竴涓剼鍗板湴璧板悜鏈潵锛?/p>
鏈潵鐨勪綘涓€瀹氫細鎰熻阿浠婂ぉ瀛︿範鐨勪綘銆?/p>
鈥斺€?蹇冪伒楦℃堡
鏈枃绔犲埌杩欓噷灏辩粨鏉熷暒~鎰熷叴瓒g殑灏忎紮浼村彲浠ュ鍒朵唬鐮佸幓璇曡瘯鍝?馃槤