Run code
Auxiliary knock code
Third-party module
choice file( file ) >>> setting( Set up ) >>> Project( project ) >>> python interpreter(python Interpreter )
Click on the gear , choice add
add to python The installation path
choice file( file ) >>> setting( Set up ) >>> Plugins( plug-in unit )
Click on Marketplace Enter the name of the plug-in you want to install such as : Translation plug-ins Input translation / Chinese plug-in Input Chinese
Select the corresponding plug-in and click install( install ) that will do
After successful installation Yes, it will pop up restart pycharm The option to Click ok , Restart to take effect
import requests # Send a request Visit website
import re
url = 'https://www.\.com/graphql'
# camouflage
headers = {
'content-type': 'application/json',
'Cookie': 'kpf=PC_WEB; kpn=KUAISHOU_VISION; clientid=3; did=web_ea128125517a46bd491ae9ccb255e242; client_key=65890b29; didv=1646739254078; _bl_uid=pCldq3L00L61qCzj6fytnk2wmhz5; userId=270932146; kuaishou.server.web_st=ChZrdWFpc2hvdS5zZXJ2ZXIud2ViLnN0EqABJBZGcI4Czt3EqaG90aWFm2EPPYcAQlkuV3ZOkHUBcqEtWV--udx6stXFOhEkGgx4tNCBS9Vhl-GstWLkvn-r_eV1072IPsO8d5sUcUuTJv3nicPWVBcfHW813ST2a4uN7HyHsnpnRkjx2BFXoMRmdSO4tbAgy3-3QRTaw05tiEp79qGRfQgVmK4kVJLOTF9X7o9vSjrLrTaRxEf0rwsXJhoSsmhEcimAl3NtJGybSc8y6sdlIiCkLEL3ZiZwp85TGjXIHaw7KGda_VNpfdZ1qigsOkLmESgFMAE; kuaishou.server.web_ph=ad8a744eb59aab3bf509625671ad16837e66',
'Host': 'www.\.com',
'Origin': 'https://www.\.com',
'Referer': 'https://www.\.com/search/video?searchKey=%E5%8F%8C%E9%A9%AC%E5%B0%BE',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
}
# The data transfer
for page in range(1, 10):
json = {
'operationName': "visionSearchPhoto",
'query': "fragment photoContent on PhotoEntity {\n id\n duration\n caption\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 __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 __typename\n}\n\nquery visionSearchPhoto($keyword: String, $pcursor: String, $searchSessionId: String, $page: String, $webPageArea: String) {\n visionSearchPhoto(keyword: $keyword, pcursor: $pcursor, searchSessionId: $searchSessionId, page: $page, webPageArea: $webPageArea) {\n result\n llsid\n webPageArea\n feeds {\n ...feedContent\n __typename\n }\n searchSessionId\n pcursor\n aladdinBanner {\n imgUrl\n link\n __typename\n }\n __typename\n }\n}\n",
'variables': {
'keyword': " dual horsetail ", 'pcursor': str(page), 'page': "search", 'searchSessionId': "MTRfMjcwOTMyMTQ2XzE2NTU3MjcyNTU3NjFf5Y-M6ams5bC-XzUwMDQ"}
}
response = requests.post(url=url, headers=headers, json=json)
<Response [200]>: The request is successful
feeds = response.json()['data']['visionSearchPhoto']['feeds']
for feed in feeds:
author_id = feed['author']['id']
photo_id = feed['photo']['id']
print(author_id, photo_id)
caption = feed['photo']['caption']
photoUrl = feed['photo']['photoUrl']
print(caption, photoUrl)
caption = re.sub('[\\/:"?<>|\\n]', '', caption)
json_like = {
Source code 、 answer 、 Tutorial can be added Q skirt :832157862 Free collection
'operationName': "visionVideoLike",
'query': "mutation visionVideoLike($photoId: String, $photoAuthorId: String, $cancel: Int, $expTag: String) {\n visionVideoLike(photoId: $photoId, photoAuthorId: $photoAuthorId, cancel: $cancel, expTag: $expTag) {\n result\n __typename\n }\n}\n",
'variables': {
'cancel': 0,
'expTag': "1_i/2005246154318902369_xpcwebsearchxxnull0",
'photoAuthorId': author_id,
'photoId': photo_id
}
}
resp_ = requests.post(url=url, headers=headers, json=json_like)
# video_data = requests.get(photoUrl).content
# with open(f'video/{caption}.mp4', mode='wb') as f:
# f.write(video_data)
Okay , My article ends here !
There are more suggestions or questions to comment on or send me a private letter ! Come on together and work hard (ง •_•)ง
If you like, just pay attention to the blogger , Or like the collection and comment on my article !!!
brief introduction :Jira It is