-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathmanual_auth_to_github.py
46 lines (30 loc) · 979 Bytes
/
manual_auth_to_github.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "ipetrash"
"""Скрипт для авторизации на github вручную"""
import requests
from lxml import etree
LOGIN = "<LOGIN>"
PASSWORD = "<PASSWORD>"
session = requests.Session()
session.headers[
"User-Agent"
] = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0"
rs = session.get("https://github.com")
print(rs)
rs = session.get("https://github.com/login")
print(rs)
root = etree.HTML(rs.content)
input_name_by_value = dict()
for input_tag in root.xpath("//input"):
try:
input_name_by_value[input_tag.attrib["name"]] = input_tag.attrib["value"]
except KeyError:
pass
input_name_by_value["login"] = LOGIN
input_name_by_value["password"] = PASSWORD
rs = session.post("https://github.com/session", data=input_name_by_value)
print(rs)
rs = session.get("https://github.com/gil9red/search_in_users_github_gists")
print(rs)
print(rs.text)