问题描述:
在使用urllib.request中的urlopen()函数的时候,url链接中含有中文字符,无法正常执行。
配置详情:
python3.x
解决方法:
使用urllib.parse中的quote()函数,将中文字符通过该函数进行url编码。
示例:
from urllib.parse import quote
from urllib.request import urlopen
s = ‘喜欢你’
s = quote(s)
url = "https://so.iqiyi.com/so/q_%s" % (s)
html = urlopen(url)