urllib.request.urlopen(url) :网络请求
urllib.parse.quote(url, safe=string.printable):将字符串转化成python解释器可以看懂的ascii形式
urllib.parse.urlencode(dict) :将字典转化成URL中的参数形式
import urllib.request
def load():
# 1 url地址
url = 'http://www.baidu.com'
# 2 get请求
response = urllib.request.urlopen(url)
print(response)
#读取内容
data = response.read()
print(data)
#将获取的内容转换成字符串
str_data = data.decode('utf-8')
# 数据写入文件
with open('baidu.html','w',encoding='utf-8') as f:
f.write(str_data)
#如果爬取回来的数据是str,但是写入本地的数据是bytes类型
#将字符串类型转换成bytes类型
str_name = 'sfj'
byte_name = str_name.encode('utf-8')
print(byte_name)
load()
import urllib.request
import urllib.parse
import string
def get_method_param