Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions requests_learn/search/sohu/shsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
}

def genqueryid(timestamp, ip, keyword, free):
ip=ip.split(".")[-1].zfill(3)
keyword=base64.b64encode(keyword.encode()).decode()[:4]
return f'{timestamp}{ip}{keyword}{free}'

def ranStr(bits):
num = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
value_set = "".join(random.sample(num, bits))
return value_set

def getip():
res = requests.get('http://myip.ipip.net', timeout=5).text
return (re.search(r"\d+\.\d+\.\d+\.\d+", res).group())

def search(key, page):
ran_str = str(int(time.time() * 1000)) + ranStr(7)
Expand All @@ -33,7 +38,8 @@ def search(key, page):
('size', '10'),
('searchType', 'news'),
('queryType', 'outside'),
('queryId', f'{str(int(time.time()))}213{base64.b64encode(key.encode()).decode()[0:4]}001'),
('ip',getip())
('queryId', genqueryid(str(int(time.time() * 1000)), ip, key, str(page).zfill(3)),
# 10位时间戳+ip最后3位+base64(key)[0:4]+001
('pvId', ran_str),
('refer', ''),
Expand Down