码迷,mamicode.com
首页 > 其他好文 > 详细

爬虫免登录进入github

时间:2019-01-22 21:45:26      阅读:323      评论:0      收藏:0      [点我收藏+]

标签:request   with open   登录   .post   cookies   name   val   rom   print   



import requests

import re
ret = requests.get(‘https://github.com/login‘)
print(ret.headers)
cookies = ret.cookies
authenticity_token=re.findall(‘name="authenticity_token" value="(.*?)"‘,ret.text)[0]    #类似csrf-token的认证
print(authenticity_token)

data={
    "login": "账号",
    "password":"密码",
"authenticity_token": authenticity_token
    }
headers={
         "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"

        }

ret = requests.post(‘https://github.com/session‘,data=data,cookies=cookies.get_dict(),headers=headers)
with open("github.html","wb") as f:
    f.write(ret.content)

爬虫免登录进入github

标签:request   with open   登录   .post   cookies   name   val   rom   print   

原文地址:https://www.cnblogs.com/Kingfan1993/p/10305973.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!