github 模拟登陆

import requests
from bs4 import BeautifulSoup

USERNAME = '  *'
PWD = '   *'

LoginUrl_GET = 'https://github.com/login'
LoginUrl = 'https://github.com/session'

headers = {
    'Host': 'github.com',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:47.0) Gecko/20100101 Firefox/47.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language': 'en-US,en;q=0.5',
    'Accept-Encoding': 'gzip, deflate, br',
    'Referer': 'https://github.com',
    'Connection': 'keep-alive',
}
formData = {
    'commit': 'Sign+in',
    'utf8': "✓",
    "login": USERNAME,
    "password": PWD,

}
s = requests.Session()
RESULT = s.get(LoginUrl_GET, headers=headers)


content = RESULT.content

with open('login.html', 'wb') as fp:
    fp.write(content)
html = open('login.html', 'r')
soup = BeautifulSoup(html, "html.parser")
token = soup.find('input', {'name': 'authenticity_token'})['value']



formData['authenticity_token'] = token





# RESULT = s.post(LoginUrl, headers=headers, data=formData,)
RESULT = s.post(LoginUrl, data=formData,)


content=RESULT.content
print RESULT.url

print RESULT.status_code
print RESULT.cookies

with open('bitbucket.html', 'w') as fp:
    fp.write(content)

https://github.com/FizLBQ/SpiderPython

关键字:python爬虫

版权声明

本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处。如若内容有涉嫌抄袭侵权/违法违规/事实不符,请点击 举报 进行投诉反馈!

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部