Python3.6 request a URL via a urllib via a Get or post method
# Coding:utf-8 from urllib import request from urllib Import Parse URL = "Http://10.1.2.151/ctower-mall-c/sys/login/logi N.do "data = {" id ":" wdb "," pwd ":" Wdb "} params=" "for key in data:params = params + key +" = "+ Data[key] +" & "P Rint ("Get method parameter:" +params) headers = {#heard部分直接通过chrome部分request header part ' Accept ': ' Application/json, Text/plain, */* ', ' accept-encoding ': ' gzip, deflate ', ' accept-language ': ' zh-cn,zh;q=0.8 ', ' Connection ': ' keep-alive ', ' C Ontent-length ': ', #get方式提交的数据长度, if it is post way, turn to get way: "id=wdb&pwd=wdb" ' content-type ': ' application/ X-www-form-urlencoded ', ' Referer ': ' http://10.1.2.151/', ' user-agent ': ' mozilla/5.0 (Linux; Android 6.0; Nexus 5 build/mra58n) applewebkit/537.36 (khtml, like Gecko) chrome/48.0.2564.23 Mobile safari/537.36 '} data = Parse.ur Lencode (data) encode (' utf-8 ') req = Request. Request (URL, headers=headers, data=data) #POST方法 #req = Request.
Request (url+params) # get Method page = Request.urlopen (req). Read ()page = Page.decode (' utf-8 ') print (page)