python - 用 requests 登陸戰(zhàn)網失敗
問題描述
想自己寫一個守望先鋒查看生涯數(shù)據(jù)的腳本不知缺少什么東西,post后200,但是登陸數(shù)據(jù)顯示未登錄
# coding: utf-8import requestsclass Career(object): def __init__(self):self.login_url = ’https://www.battlenet.com.cn/login/zh/?ref=https://www.battlenet.com.cn/oauth/authorize?client_id%3Dnetease-sc2-esports%26response_type%3Dcode%26scope%3Did%2Bbattletag%2Blogout%2Bprofile%2Bprivate_games%26redirect_uri%3Dhttps%253A%252F%252Faccount.bnet.163.com%252Fbattlenet%252Flogin%253Finner_client_id%253Dow%2526inner_redirect_uri%253Dhttp%25253A%25252F%25252Fow.blizzard.cn%25252Fbattlenet%25252Flogin%25253Fredirect_url%25253Dhttp%2525253A%2525252F%2525252Fow.blizzard.cn%2525252Fcareer%2525252F&app=oauth’self.career_url = ’http://ow.blizzard.cn/career/’self.headsers = { ’Host’: ’www.battlenet.com.cn’, ’Connection’: ’keep-alive’, ’Cache-Control’: ’max-age=0’, ’Origin’: ’https://www.battlenet.com.cn’, ’User-Agent’: ’Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36’, ’Content-Type’: ’application/x-www-form-urlencoded’, ’Accept’: ’text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8’, ’DNT’: ’1’, ’Accept-Encoding’: ’gzip, deflate, br’, ’Accept-Language’: ’zh-CN,en-US;q=0.8,en;q=0.6,zh;q=0.4’}self.form_data = { ’accountName’: ’***’, ’password’: ’***’,} def login(self):session = requests.session()session.headers = self.headsersa = session.post(url=self.login_url, data=self.form_data)html = session.get(url=self.career_url)print(html.text)instance = Career()instance.login()
問題解答
回答1:Form_Data里的信息有不少呢,看看是不是因為這個。
這樣呢?
def login(self):session = requests.session()session.headers.update(self.headsers)a = session.post(url=self.login_url, data=self.form_data)html = session.get(url=self.career_url)print(html.text)
相關文章:
1. android - 分享到微信,如何快速轉換成字節(jié)數(shù)組2. angular.js - Beego 與 AngularJS的模板格式沖突,該怎么解決?3. javascript - 能否讓vue-cli的express修改express重啟服務4. 解決Android webview設置cookie和cookie丟失的問題5. node.js - npm一直提示proxy有問題6. phpstorm 沒有安裝Emmet怎么還有Emmet的相關功能啊7. python - flask template file not found8. mysql怎么多表刪除啊?9. javascript - 有沒有iOS微信中可以在背景播放視頻的方法?10. python - 網頁title中包含換行,如何用正則表達式提取出來?
