Skip to content

Commit 79d6b88

Browse files
authored
Merge pull request #34 from ySirius/main
拉取评论时候添加cookie
2 parents e6c4c29 + 19586b7 commit 79d6b88

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

auto_comment_plus.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ def main(opts=None):
675675
logger.debug('Closed the configuration file')
676676
logger.debug('Configurations in Python-dict format: %s', cfg)
677677
ck = cfg['user']['cookie']
678+
jdspider.cookie = ck.encode("utf-8")
678679

679680
headers = {
680681
'cookie': ck.encode("utf-8"),

config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
user:
2-
cookie: ''
2+
cookie: ''

jdspider.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717

1818
# Reference: https://github.com/fxsjy/jieba/blob/1e20c89b66f56c9301b0feed211733ffaa1bd72a/jieba/__init__.py#L27
19+
cookie = ""
1920
log_console = logging.StreamHandler(sys.stderr)
2021
default_logger = logging.getLogger('jdspider')
2122
default_logger.setLevel(logging.DEBUG)
@@ -68,7 +69,8 @@ def getParamUrl(self, productid, page, score):
6869

6970
def getHeaders(self, productid): # 和初始的self.header不同,这是爬取某个商品的header,加入了商品id,我也不知道去掉了会怎样。
7071
header = {"Referer": "https://item.jd.com/%s.html" % (productid),
71-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"
72+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36",
73+
"cookie" : cookie
7274
}
7375
return header
7476

0 commit comments

Comments
 (0)