Skip to content

Commit 716cd36

Browse files
committed
Supplement and improve the request header
1 parent c91f57f commit 716cd36

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

auto_comment_plus.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,22 @@
2626

2727
headers = {
2828
'cookie': ck,
29-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/'
30-
'537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/'
31-
'537.36'
29+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36',
30+
'Connection': 'keep-alive',
31+
'Cache-Control': 'max-age=0',
32+
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="98", "Google Chrome";v="98"',
33+
'sec-ch-ua-mobile': '?0',
34+
'sec-ch-ua-platform': '"Windows"',
35+
'DNT': '1',
36+
'Upgrade-Insecure-Requests': '1',
37+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
38+
'Sec-Fetch-Site': 'same-site',
39+
'Sec-Fetch-Mode': 'navigate',
40+
'Sec-Fetch-User': '?1',
41+
'Sec-Fetch-Dest': 'document',
42+
'Referer': 'https://order.jd.com/',
43+
'Accept-Encoding': 'gzip, deflate, br',
44+
'Accept-Language': 'zh-CN,zh;q=0.9',
3245
}
3346
# 评价生成
3447
def generation(pname, _class=0, _type=1):
@@ -58,9 +71,9 @@ def generation(pname, _class=0, _type=1):
5871
else:
5972
comments = ''
6073
if _type == 1:
61-
num = 8
74+
num = 6
6275
elif _type == 0:
63-
num = 5
76+
num = 4
6477
if len(result) < num :
6578
num = len(result)
6679
else:

jdspider.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,21 @@ def __init__(self, categlory):
2525
quote(categlory))
2626
self.commentBaseUrl = "https://sclub.jd.com/comment/productPageComments.action?"
2727
self.headers = {
28-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36', }
28+
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
29+
'accept-encoding': 'gzip, deflate, br',
30+
'accept-language':'zh-CN,zh;q=0.9',
31+
'cache-control': 'max-age=0',
32+
'dnt':'1',
33+
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="98", "Google Chrome";v="98"',
34+
'sec-ch-ua-mobile': '?0',
35+
'sec-ch-ua-platform': '"Windows"',
36+
'sec-fetch-dest': 'document',
37+
'sec-fetch-mode':' navigate',
38+
'sec-fetch-site':'none',
39+
'sec-fetch-user': '?1',
40+
'upgrade-insecure-requests': '1',
41+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36'
42+
}
2943
self.productsId = self.getId()
3044
self.comtype = {1: "nagetive", 2: "medium", 3: "positive"}
3145
self.categlory = categlory

0 commit comments

Comments
 (0)