The Urllib.request module is python3 for handling URLs.
1. First Import:
From Urllib Import Request
2. Construct the URL, construct the URL's headers information and send the reference "request." Request "
----GET request with no parameters "slightly"
----GET request with parameters "with header, with data, with header and data, with pre-issued host"
Import: from Urllib Import parse
Import JSON
url = r "xxxxx" NOTE: If you configure host, the host domain name in the address will be rewritten as the host address "
headers = {' Host ': ' Domain name ',
' Cookie ' = ' xxxx ',
}
data = {' CANSHU1 ' = AAA,
' Canshu2 ' = BBB,
' Canshu3 ' = CCC,
' Canshu4 ' = ddd
}
data = Parse.urlencode (data). Encode (' Utf-8 ')
req = Request. Request (Url,headers=headers,data=data)
3. Request the URL "Request.urlopen" and get the return parameter ". Read ()"
page = Request.urlopen (req). Read
page = Page.decode (utf-8)
4. Convert the returned JSON format to Python's data Structure "json.loads (XX)"
Page_python = json.loads (page)
5. Parse the returned data type and loop through the desired content multiple times
--Print data type: print (Type (a))
--Direct Fetch dictionary value value: page_python[' key value 1 ' [' Key value 2 '] [' key value 3 ']
Python Interface Automation Test (i)-request module