python模拟登陆
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                python模拟登陆
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                簡單使用python(python3.7)模擬登陸github
# !/usr/bin/env python # -*-coding:utf-8-*- """ @Author? : xiaofeng @Time? ? : 2018/12/18 16:31 @Desc : Less interests,More interest. (模擬登陸github) @Project : python_appliction @FileName: github.py @Software: PyCharm @Blog? ? :https://blog.csdn.net/zwx19921215 """import bs4 import requests# 聲明頭信息 headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0' }login_url = 'https://github.com/login' login_post = 'https://github.com/session' session = requests.session()""" 獲取authenticity_token """def get_token():response = session.get(url=login_url, headers=headers)soup = bs4.BeautifulSoup(response.text, 'html.parser')# xx = soup.find('input', {'id': 'xxx'}).get('value')token = soup.find('input', {'name': 'authenticity_token'}).get('value')print(token)return token""" 模擬登陸 """def sign_in(username, password):form_data = {'commit': 'Sign in','utf8': '?','authenticity_token': get_token(),'login': username,'password': password}response = session.post(url=login_post, data=form_data, headers=headers)if response.status_code == 200:print("congratulations login success ^_^")print(response.text)if __name__ == '__main__':sign_in('username', 'password')?
總結(jié)
以上是生活随笔為你收集整理的python模拟登陆的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: n卡eth挖矿设置_以太坊挖矿软件配置(
 - 下一篇: pycharm的配置_pycharm怎么