Skip to content

Commit

Permalink
补充部分注释
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghyw committed Dec 22, 2020
1 parent 1835c6a commit c004e85
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion jd_spider_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ class QrLogin:
def __init__(self, spider_session: SpiderSession):
"""
初始化扫码登录
大致流程:
1、访问登录二维码页面,获取Token
2、使用Token获取票据
3、校验票据
:param spider_session:
"""
self.qrcode_img_file = 'QRcode.png'
self.qrcode_img_file = 'qr_code.png'

self.spider_session = spider_session
self.session = self.spider_session.get_session()
Expand All @@ -115,6 +119,10 @@ def __init__(self, spider_session: SpiderSession):
self.refresh_login_status()

def refresh_login_status(self):
"""
刷新是否登录状态
:return:
"""
self.is_login = self._validate_cookies()

def _validate_cookies(self):
Expand Down Expand Up @@ -145,6 +153,10 @@ def _get_login_page(self):
return page

def _get_qrcode(self):
"""
缓存并展示登录二维码
:return:
"""
url = 'https://qr.m.jd.com/show'
payload = {
'appid': 133,
Expand All @@ -167,6 +179,10 @@ def _get_qrcode(self):
return True

def _get_qrcode_ticket(self):
"""
通过 token 获取票据
:return:
"""
url = 'https://qr.m.jd.com/check'
payload = {
'appid': '133',
Expand All @@ -193,6 +209,11 @@ def _get_qrcode_ticket(self):
return resp_json['ticket']

def _validate_qrcode_ticket(self, ticket):
"""
通过已获取的票据进行校验
:param ticket: 已获取的票据
:return:
"""
url = 'https://passport.jd.com/uc/qrCodeTicketValidation'
headers = {
'User-Agent': self.spider_session.get_user_agent(),
Expand Down

0 comments on commit c004e85

Please sign in to comment.