python 模拟登陆

来源:互联网 发布:散热器设计软件 编辑:程序博客网 时间:2024/06/03 16:06

python 模拟登陆 


#模拟登陆from urllib import request, parsedef login(url):    print('Login ...')    username = input('username: ')    password = input('password: ')    login_data = parse.urlencode(        [            ('username', username),            ('userpwd', password),            ('yzm','test')        ]    )        #网络访问提交到的地址    req = request.Request(url)    #防跨域设置HTTP源头地址  早期浏览器非规范参数    req.add_header('Origin', url)    #防跨域设置HTTP源头地址  标准浏览器规范参数    req.add_header('Referer', url)    #模拟提交的浏览器类型    req.add_header('User-Agent', 'Mozilla/6.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/8.0 Mobile/10A5376e Safari/8536.25')        with request.urlopen(req, data=login_data.encode('utf-8')) as f:        print(f.info())        print('Data:', f.read().decode('utf-8'))                login('http://127.0.0.1/pas/a.py')


原创粉丝点击