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

2)实现github自动登陆获取信息

时间:2018-06-03 19:37:40      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:import   erb   jee   dict   put   input   成功   rdl   更新   

# -*- coding:utf-8 -*-
# __author__ = ‘lixiang‘
# 实现github自动登陆和获取数据

import requests
from bs4 import BeautifulSoup


#第一步获取github的CSRFtoken
r1=requests.get(url="https://github.com/login")
bs=BeautifulSoup(r1.text,features="html.parser")
tag=bs.find(name="input",attrs={"name":"authenticity_token"})
csrftoken=tag.attrs.get("value")
r1_cookies=r1.cookies.get_dict()

#第二步登陆,要带第一次的cookie,给他授权
post_dict={
    "commit":"Sign in",
    "utf8":"?",
    "authenticity_token":csrftoken,
    "login":"xxx",
    "password":"xxx"
}

r2=requests.post(
        url="https://github.com/session",
        data=post_dict,
        cookies=r1_cookies,
   )

#登录成功获取cookie
r2_cookies=r2.cookies.get_dict()


print(r1_cookies)
print(r2_cookies)
"""
{‘logged_in‘: ‘no‘, ‘_gh_sess‘: ‘aFVOSWJqVTJwRjVxZmg0ZmxYNldCNCtPYVdseENaNlBCTzdXTG1ZZVUxNHdHbWNhZzA5ekRvdXhTWmpzTzJHVEVOTWh1R0dWenNkWFVrRlhST1J3TTZISER0eGFveHRleXlad0F2Z2xMQ1RDbldQN2UvRjNCelRadmNFNWs2Z1h2LzlJdmdMUU40UGpZTVBqWDNnRDJla1ErblNWTFlaSzFscUh0T0dvMThDL2kxeEdESUF5bTdlOXM3Q0E2Y1FrSzdGdjVScTVNaHBkU25jNEZiVm91V0dYaUQ4Q2lUTkxycjRWdlR6Q2NrTGJBLzR3L1NyTlViYmFEeEpuRVEvUGh1T0xScVV6S1c5OTRFVElkUlVDMDJXM1kwd2Y3d09IWjFBa0ZvWXJNNmxOQlJJcFN3VitFalZSZFRVMk9Cd00tLTdJeE01dFhuR01sYmdZVmUvK2FZOWc9PQ%3D%3D--74f6aa35aadf3a7f53d2a2c9c84196ea680284fb‘}
{‘logged_in‘: ‘yes‘, ‘__Host-user_session_same_site‘: ‘p9mOvXkKsooBAWnzaWI4MTCEY2NcMfOQ6ZplGjIdE-buENW-‘, ‘_gh_sess‘: ‘alU5c290U1Y2aXZPVEVFTjdUWEpWUnpMdVUrVjNsZmJCU2Vrdi9VL3R1N0hVK2w1MkFMUmdOaDRXdXYwditsRm1IOU5jbVlBQ1MzbHI3R2p3dGlhdnFuYWZUWENzN3FwK3QzZStpeHo1ZmttS3Nmb2Fmbm5DRWhCbWpNbjdNQU01T3NJYWs4ZVhUaks3aVNQSjdOZzhUUmNPTm5kT21qZ1dpMFFwd3JkTmVURjNUU0hnK2cyNXdkd1hTZVZxTjl0NzVoV1V3eDhSNGJtM3FRaDRxejNWTUZuQjkyay9KN2NSdDB2TU1tSm1WS3dmaHdXL3ZUS3VEQWVnVUJLRGRkc1Axa09VV1VpU3BSWnp3L3pYRGo5WDZoVGVwZXovbG9uVk5hZTBFbTBtM0VhRHJmYzZHMUxBM3JYWHJ2R1F2NW9oT3prdlpOYmZMbk1PYUpPbVpBQS91bWxSWHJzM1IrNVYwSzI1TzIwdUFtUjRWRWFmb3A0SEd4VlZRcE8yRmt5YThvc1FEcGJNeGNwRGdQZ3ZHeGJzTXlkY3MyN05zdjhVUDhzbmNGQWFPRlJBQ1RuZXQvRFYrU3JaVk5zVXhkaC0tQnZ1MXdGbzBWK0gzNjlxTzJFdUhkdz09--cdbc5200af5265fbfc5e9c45c9e3cf5a6872d542‘, ‘user_session‘: ‘p9mOvXkKsooBAWnzaWI4MTCEY2NcMfOQ6ZplGjIdE-buENW-‘}

"""
#把r2_cookies更新到r1_cookies
r1_cookies.update(r2_cookies)
#获取仓库信息
r3=requests.get(
    url="https://github.com/settings/repositories",
    cookies=r1_cookies
)
print(r3.text)

 

2)实现github自动登陆获取信息

标签:import   erb   jee   dict   put   input   成功   rdl   更新   

原文地址:https://www.cnblogs.com/lixiang1013/p/9129865.html

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