2018-12-04-Python全栈开发-day92-自动登录

1.自动登录知乎

2.自动登录博客园

3.自动登录github

  

import requests
from bs4 import BeautifulSoup

get_token = requests.get(
    url='https://github.com/'
)

soup = BeautifulSoup(get_token.text,'html.parser')

token1 = soup.find(attrs={'name':'authenticity_token'}).get('value')#得到第一次登录的token

#开始自动登录
data={
    'commit':'Sign in',
    'utf-8':'',
    'authenticity_token':token1,
    'login':'xxx,#在此输入账号
    'password':'xx'#在此输入密码
}

login1 = requests.post(
    url='https://github.com/session',
    data=data
)
log_profile = requests.get(
    url='https://github.com/xx'#此处xx为用户名
)
print(log_profile.text)

 

posted @ 2018-12-04 22:46  brownbearye  阅读(159)  评论(0)    收藏  举报