爬虫请求出现UnicodeEncodeError: 'latin-1' codec can't encode characters

记录下,这个查了好多问题,正常是headers或者链接里%**这个与中文转化的问题,转化成链接里的格式替换就可以,用import urllib库

import urllib
key="酸奶"
key=urllib.parse.quote(key)
print(key)
key1=urllib.parse.unquote(key)
print(key1)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42357472/article/details/85260585