
from urllib.request import urlopen |
from urllib.parse import quote,urlencode#两种用来将中文转出%%%%形式的不同方式 |
key = input('请输入一个查询关键字') |
print(quote(key))#转码方式1:将key转成%%%%% |
args = { |
'wd' : key, |
'ie' : 'utf-8' |
} #转码方式2(以字典形式): wd=%%%%&ie=utf-8 |
print(urlencode(args)) |
#url = 'http://www.baidu.com/s?wd' + quote(key)#对应方式1 |
url = 'http://www.baidu.com/s?' + urlencode(args)#对应方法2 |
response = urlopen(url)#get请求 |
print(response.read().decode()) |



