Skip to content

Commit

Permalink
for captcha
Browse files Browse the repository at this point in the history
  • Loading branch information
kanghua309 committed Sep 13, 2017
1 parent 56e2e94 commit 46c4005
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions easytrader/xqtrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
from numbers import Number

import requests
import shutil
#from urlparse import urlparse

from .log import log
from .webtrader import NotLoginError, TradeError
from .webtrader import WebTrader

from matplotlib import pyplot as plt
from PIL import Image

UID = "191505195949401"
devideID = "2caec7b60c2cd8c108942f835508d051"


class XueQiuTrader(WebTrader):
config_path = os.path.dirname(__file__) + '/config/xq.json'
Expand Down Expand Up @@ -49,7 +57,7 @@ def autologin(self, **kwargs):
"""
self.login()

def login(self, throw=False):
def login(self,,throw=False):
"""
登录
:param throw:
Expand All @@ -58,7 +66,7 @@ def login(self, throw=False):
login_status, result = self.post_login_data()
if login_status is False and throw:
raise NotLoginError(result)
log.debug('login status: %s' % result)

return login_status

def _prepare_account(self, user='', password='', **kwargs):
Expand Down Expand Up @@ -91,9 +99,29 @@ def post_login_data(self):
'areacode': '86',
'telephone': self.account_config['account'],
'remember_me': '0',
'password': self.account_config['password']
'password': self.account_config['password'],
}
login_response = self.session.post(self.config['login_api'], data=login_post_data)
#login_status = login_response.json()
#if 'error_description' in login_status:
# return False, login_status['error_description']

#u = urlparse('https://xueqiu.com/')
c = requests.cookies.RequestsCookieJar()
c.set('u', UID, path='/', domain='xueqiu.com')
c.set('device_id', devideID, path='/', domain='xueqiu.com')
self.session.cookies.update(c)
self.session.get('https://xueqiu.com/service/captcha/sid/id')
resp = self.session.get('https://xueqiu.com/service/captcha/image', stream=True)
with open('/tmp/captcha.jpg', 'wb') as out_file:
shutil.copyfileobj(resp.raw, out_file)
img = Image.open('/tmp/captcha.jpg')
plt.figure("captcha")
plt.imshow(img)
plt.axis('off')
plt.show()
login_post_data['captcha'] = raw_input('please input the captcha:')
login_response = self.session.post(self.config['login_api'], data=login_post_data)
login_status = login_response.json()
if 'error_description' in login_status:
return False, login_status['error_description']
Expand Down

0 comments on commit 46c4005

Please sign in to comment.