python 2.7 简单模拟登陆网站
举个栗子,首先创建网络会话,
然后就可以用创建的session来访问网页了。
session.get(URL)
#-*- coding:utf-8 -*- import requests import re from hashlib import md5 domain = 'http://*********:0000' def login_session(username, password): data = { 'method': 'verify', 'USERNAME': username, 'PASSWORD': md5(password).hexdigest().upper() } http = requests.Session() res = http.get(domain + '/example/eg', params=data) with open("res.txt","a") as f: #方便调试观察 f.write(res.text.encode("utf-8")) #/ return http if __name__=='__main__': session = login_session(USER,PW)
some_html = session.get(domain + "/")