import requests
from pyquery import PyQuery as pq
class Login(object):
def __init__(self):
self.headers = {
'Referer': 'https://github.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36',
'Host': 'github.com'
}
self.login_url = 'https://github.com/login'
self.post_url = 'https://github.com/session'
self.feed_url = 'https://github.com/dashboard-feed'
self.logined_url = 'https://github.com/settings/profile'
self.session = requests.Session()
def get_authenticity_token(self):
response = self.session.get(self.login_url, headers=self.headers)
doc=pq(response.text)
token=doc('input[name="authenticity_token"]').attr('value')
return token
def get_ga_id(self):
response=self.session.get(self.login_url,headers=self.headers)
doc=pq(response.text)
ga_id=doc('input[class="js-octo-ga-id-input"]').attr('value')
return ga_id
def get_timestamp(self):
response = self.session.get(self.login_url, headers=self.headers)
doc = pq(response.text)
timestamp=doc('input[name=timestamp]').attr('value')
return timestamp
def get_timestamp_secret(self):
response = self.session.get(self.login_url, headers=self.headers)
doc = pq(response.text)
timestamp_secret=doc('input[name=timestamp_secret]').attr('value')
return timestamp_secret
def login(self, email, password):
post_data = {
'commit': 'Sign in',
'utf8': '✓',
'authenticity_token': self.get_authenticity_token(),
'ga_id': self.get_ga_id(),
'login': email,
'password': password,
'webauthn-support':'supported',
'webauthn-iuvpaa-support':'supported',
'timestamp':self.get_timestamp(),
'timestamp_secret':self.get_timestamp_secret(),
}
response = self.session.post(self.post_url, data=post_data, headers=self.headers)
response=self.session.get(self.feed_url,headers=self.headers)
if response.status_code == 200:
self.dynamics(response.text)
response = self.session.get(self.logined_url, headers=self.headers)
if response.status_code == 200:
self.profile(response.text)
def dynamics(self, html):
doc = pq(html)
dynamics = doc('div[class="d-flex flex-items-baseline"] div')
for item in dynamics.items():
dynamic = item.text().strip()
print(dynamic)
dynamics = doc('div[class="d-flex flex-justify-between flex-items-baseline"] div')
for item in dynamics.items():
dynamic = item.text().strip()
print(dynamic)
def profile(self, html):
doc=pq(html)
name = doc('input[name="user[profile_name]"]').attr('value')
print(name)
if __name__ == "__main__":
login = Login()
login.login(email='1179380391@qq.com', password='wjh07233')