URL 中特殊字符,保险起见,先进行编码再发起请求.

如:

url = "https://dd.ccc.com/thumb_20200215160431_2980_u=1141259048,554497535&fm=26&gp=0/u=1141259048,554497535&fm=26&gp=0.jpg"

实现:

import urllib.parse

url = "https://dd.ccc.com/thumb_20200215160431_2980_u=1141259048,554497535&fm=26&gp=0/u=1141259048,554497535&fm=26&gp=0.jpg"

#encode
encode_url = urllib.parse.quote(url)
#'https%3A//dd.ccc.com/thumb_20200215160431_2980_u%3D1141259048%2C554497535%26fm%3D26%26gp%3D0/u%3D1141259048%2C554497535%26fm%3D26%26gp%3D0.jpg'

#decode
decode_url = urllib.parse.unquote(encode_url)

assert url == decode_url
Last modification:May 13th, 2022 at 02:38 pm