程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python crawler series a sound web version_ Signature algorithm

編輯:Python

Python Crawler series of a voice web version _signature Algorithm

Welcome to technical communication > Click here to contact us <

The code is for learning and communication only , Do not use for illegal purposes

Go straight to the code

import requests
import execjs
from sign import sign
retry = 3
timeout = 30
headers = {

"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Mobile Safari/537.36",
}
def doRequest(url, param):
'''
Initiate request
'''
for i in range(retry):
try:
param = sign(param)
url += param
resp = requests.get(url, headers=headers, timeout=timeout)
return resp.json
except Exception as e:
pass
def userProfile(sec_user_id):
'''
Get user details
'''
url = "https://www.*****.com/aweme/v1/web/user/profile/other/"
params = {

"device_platform": "webapp",
"aid": "6383",
"channel": "channel_pc_web",
"publish_video_strategy_type": "2",
"source": "channel_pc_web",
"sec_user_id": sec_user_id,
"version_code": "160100",
"version_name": "16.1.0",
"cookie_enabled": "true",
"screen_width": "1920",
"screen_height": "1080",
"browser_language": "zh-CN",
"browser_platform": "Win32",
"browser_name": "Mozilla",
"browser_version": "5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36 SE 2.X MetaSr 1.0",
"browser_online": "true",
}
res = doRequest(url, params)
print(res)
def getRecommIndexVideo():
'''
Get home page recommendation video
'''
url = "https://www.*****.com/aweme/v1/web/channel/feed/"
params = {

"device_platform": "webapp",
"aid": 6383,
"channel": "channel_pc_web",
"tag_id": "",
"count": 10,
"version_code": "160100",
"version_name": "16.1.0",
"cookie_enabled": true,
"screen_width": 1280,
"screen_height": 720,
"browser_language": "zh-CN",
"browser_platform": "Win32",
"browser_name": "Mozilla",
"browser_version": "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36",
"browser_online": true
}
res = doRequest(url, params)
print(res)
def searchVideo(keyword):
'''
Video search
'''
url = "https://www.*****.com/aweme/v1/web/search/item/"
params = {

"device_platform": "webapp",
"aid": 6383,
"channel": "channel_pc_web",
"search_channel": "aweme_video_web",
"sort_type": "0",
"publish_time": "0",
"keyword": keyword,
"search_source": "normal_search",
"query_correct_type": "1",
"is_filter_search": "0",
"offset": 0,
"count": 24,
"version_code": "160100",
"version_name": "16.1.0",
"cookie_enabled": true,
"screen_width": 1280,
"screen_height": 720,
"browser_language": "zh-CN",
"browser_platform": "Win32",
"browser_name": "Mozilla",
"browser_version": "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36",
"browser_online": true
}
res = doRequest(url, params)
print(res)
if __name__ == '__main__':
# User details ( The request requires a tape cookie)
# userProfile'MS4wLjABAAAAmtr5MWCsxiV7NZMCuXkoCHKXtRyRlomFTVgw8h3sJNo')
# Home page recommended video
# getRecommIndexVideo()
# Search video
# searchVideo(" Journalism ")
....
.....
if __name__ == '__main__':
main()

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved