Skip to content

Commit

Permalink
Qimai:star:
Browse files Browse the repository at this point in the history
  • Loading branch information
Henryhaohao committed Nov 12, 2018
1 parent 6df1579 commit f2666d8
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
Binary file added Pic/login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

## :dolphin:介绍
### 该项目为爬取[七麦数据](https://www.qimai.cn/rank)平台APP榜单数据
- 爬虫文件:Spiders目录下的qimai.py
- JS解密文件:Spiders目录下的encrypt.js
- **20181112 - 增加七麦数据的登录代码(qimai_login.py),因为有小伙伴反映有些数据(例如关键字排名搜索需要用户登录才可以)**
- **爬虫文件:Spiders目录下的qimai.py**
- **JS解密文件:Spiders目录下的encrypt.js**
## :dolphin:运行环境
Version: Python3
## :dolphin:安装依赖库
Expand All @@ -27,6 +28,7 @@ pip3 install -r requirements.txt
![enter image description here](Pic/data.png)

> - **运行截图**<br><br>
![enter image description here](Pic/login.png)
![enter image description here](Pic/run.png)
![enter image description here](Pic/data_1.png)
## :dolphin:**总结**
Expand Down
Binary file added Spiders/captcha.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions Spiders/qimai_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# !/user/bin/env python
# -*- coding:utf-8 -*-
# time: 2018/11/12--11:48
__author__ = 'Henry'



'''
项目:七麦数据登录 (登录后可以查看更多种数据)
'''


import requests,execjs,json,urllib.parse,time

req = requests.Session()
with open('encrypt.js',encoding='utf-8') as f:
jsdata = f.read()
jsdata = execjs.compile(jsdata)

def qimai_login():
# 获取set-cookie
# 1
url = 'https://www.qimai.cn/account/signin/r/%2F'
headers = {
'Referer':'https://www.qimai.cn/rank',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
}
html = req.get(url,headers=headers)
# 2
url = 'https://api.qimai.cn/account/pageCheck/type/signin'
analysis = jsdata.call('get_analysis',url,'{}') # 登录不用传递params,为空{}
analysis = json.loads(analysis).get('analysis')
url = 'https://api.qimai.cn/account/pageCheck/type/signin?analysis={}'.format(urllib.parse.quote(analysis))
html = req.get(url,headers=headers)
print(html.text)
# 3
url = 'https://api.qimai.cn/account/userinfo'
analysis = jsdata.call('get_analysis',url,'{}') # 登录不用传递params,为空{}
analysis = json.loads(analysis).get('analysis')
url = 'https://api.qimai.cn/account/userinfo?analysis={}'.format(urllib.parse.quote(analysis))
html = req.get(url,headers=headers)
print(html.text)
# 4
url = 'https://api.qimai.cn/index/index'
analysis = jsdata.call('get_analysis',url,'{}') # 登录不用传递params,为空{}
analysis = json.loads(analysis).get('analysis')
url = 'https://api.qimai.cn/index/index?analysis={}'.format(urllib.parse.quote(analysis))
html = req.get(url,headers=headers)
print(html.text)
# 5
url = 'https://api.qimai.cn/account/getVerifyCodeImage?{}'.format(str(int(time.time()*1000)))
html = req.get(url,headers=headers)
with open('captcha.jpg','wb') as f:
f.write(html.content)
# 6 提交登录
captcha = input('请输入验证码:')
url = 'https://api.qimai.cn/account/signinForm'
analysis = jsdata.call('get_analysis',url,'{}') # 登录不用传递params,为空{}
analysis = json.loads(analysis).get('analysis')
login_url = 'https://api.qimai.cn/account/signinForm?analysis={}'.format(urllib.parse.quote(analysis))
data = {
'username':username,
'password':password,
'code':captcha, # 验证码
}
html = requests.post(login_url,data=data,headers=headers)
print(html.json())
if html.json().get('msg') == '登录成功':
print('登录成功!用户名为:' + html.json().get('userinfo').get('username'))
print('获取Cookie:' + html.headers.get('Set-Cookie')) # USERINFO 就是登录成功返回的cookie
elif html.json().get('msg') == '验证码错误,请重试':
print('验证码错误,请重试!')
elif html.json().get('msg') == '用户名或密码错误':
print('用户名或密码错误')


if __name__ == '__main__':
username = input('请输入你的七麦账号:')
password = input('请输入你的七麦密码:')
qimai_login()

0 comments on commit f2666d8

Please sign in to comment.