- 帖子
- 7
- 精华
- 0
- 积分
- 52
- 阅读权限
- 20
- 注册时间
- 2020-10-14
- 最后登录
- 2020-11-2
|
第三题:- '''
- 模拟登陆豆瓣
- '''
- import requests
- import urllib3
- urllib3.disable_warnings()
- base_url = "https://www.douban.com"
- headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"}
- session = requests.session()
- # 获取cookie
- def get_cookies():
- r = session.get(base_url,headers = headers,verify = False)
- cookies = r.cookies
- return cookies
- # 登录
- def login(name,password):
- login_url = "https://accounts.douban.com/j/mobile/login/basic"
- data = {"ck":"","remember":"true","name":name,"password":password}
- r = session.post(login_url, headers = headers, data=data)
- return r
- # 发表广播
- def post(comment):
- cookies = get_cookies()
- ck = cookies["ck"]
- post_data = {"ck":ck,"comment": comment,"privacy_and_reply_limit": "X,"}
- res = session.post(base_url,headers = headers,data = post_data)
- if __name__ == "__main__":
- get_cookies()
- login("username","password")
- post("今天天气真好!")
复制代码 |
|