【python】urlopen中的url含有中文问题

问题描述:

在使用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)

 

发布了22 篇原创文章 · 获赞 3 · 访问量 1897

猜你喜欢

转载自blog.csdn.net/weixin_44322399/article/details/102860302