1.开头
网上搜了一大堆没见过对的
2.代码如下
#! /usr/bin/env python3
#__author__=weiimport urllib.parse
import ssl
import urllib.requestSETTING_PROXY=1
HTTPS=1if HTTPS:url = 'https://www.baidu.com/'
else:url = 'http://www.baidu.com/'user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
values = { 'name' : 'xxx1', 'email' : 'fuck@qq.com', 'password' : '123456' }
headers = { 'User-Agent' : user_agent }if SETTING_PROXY:ssl._create_default_https_context = ssl._create_unverified_context#https://blog.csdn.net/qq_25403205/article/details/81258327if HTTPS:proxy_support=urllib.request.ProxyHandler({"https":"127.0.0.1:8080"})else:proxy_support=urllib.request.ProxyHandler({"http":"127.0.0.1:8080"})opener=urllib.request.build_opener(proxy_support)urllib.request.install_opener(opener)data = urllib.parse.urlencode(values).encode(encoding='UTF8')#if you don't encode utf, TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.
req = urllib.request.Request(url,data=data,headers=headers)
response = urllib.request.urlopen(req)
the_page = response.read()print(the_page.decode("utf8"))
3.结果
抓的包如下