import urllib.request
import urllib.parse
import http.cookiejar
def gethtml(url):
cj = http.cookiejar.CookieJar()
cookie_jar = urllib.request.HTTPCookieProcessor(cj)
opener = urllib.request.build_opener(cookie_jar)
urllib.request.install_opener(opener)
page = urllib.request.urlopen('*******')
for index, cookie in enumerate(cj):
print ('[',index, ']',cookie)
data = {
'username':'****',
'password':'****',
'execution':'e1s1',
'lt':'LT-68105-mdbC4YmMWgjyDwVV5bI3jOWfo0FCcb-1440307068488',
'_eventId':'submit',
'rmShown':'1'
}
postdata = urllib.parse.urlencode(data).encode('utf-8')
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36',
'Referer':'******'}
req = urllib.request.Request(url,data=postdata,headers=headers)
response = urllib.request.urlopen(req)
return response.read()
def getgrade(url):
html = gethtml(url).decode('utf-8')
print(html)
if name == '__main__':
url = '******'
getgrade(url)
第一个print语句可以打印出两行cookie 第二个print html一直打印的登陆界面,求高手指教。。