-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathdouban.py
61 lines (52 loc) · 1.57 KB
/
douban.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
"""
info:
author:CriseLYJ
github:https://github.com/CriseLYJ/
update_time:2019-04-04
"""
"""
模拟登陆豆瓣
"""
class DouBanLogin(object):
def __init__(self, account, password):
self.url = "https://accounts.douban.com/j/mobile/login/basic"
self.headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36"
}
"""初始化数据"""
self.data = {
"ck": "",
"name": account,
"password": password,
"remember": "true",
"ticket": ""
}
self.session = requests.Session()
def get_cookie(self):
"""模拟登陆获取cookie"""
html = self.session.post(
url=self.url,
headers=self.headers,
data=self.data
).json()
if html["status"] == "success":
print("恭喜你,登陆成功")
def get_user_data(self):
"""获取用户数据表明登陆成功"""
# TODO: 这里填写你用户主页的url
url = "这里填写你用户主页的url"
# 获取用户信息页面
html = self.session.get(url).text
print(html)
def run(self):
"""运行程序"""
self.get_cookie()
self.get_user_data()
if __name__ == '__main__':
account = input("请输入你的账号:")
password = input("请输入你的密码:")
login = DouBanLogin(account, password)
login.run()