关于python:http协议uri编码

44次阅读

共计 361 个字符,预计需要花费 1 分钟才能阅读完成。

import urllib.parse
import string
import requests

url = 'https://baidu.com/s?'

params = {
    'wd': "中文",
    'key': "baidu",
    'value': "name"
}

str_params = urllib.parse.urlencode(params)
parse_url = url + str_params

end_url = urllib.parse.quote(parse_url, string.printable) # https://baidu.com/s?wd=%E4%B8%AD%E6%96%87&key=baidu&value=name
response = requests.get(end_url)
print(response.content.decode())

正文完
 0