python通过urllib2获取带有中文参数url内容的方法
作者:pythoner 时间:2022-07-26 10:35:58
本文实例讲述了python通过urllib2获取带有中文参数url内容的方法。分享给大家供大家参考。具体如下:
对于中文的参数如果不进行编码的话,python的urllib2直接处理会报错,我们可以先将中文转换成utf-8编码,然后使用urllib2.quote方法对参数进行url编码后传递。
content = u'你好 jb51.net'
content = content.encode('utf-8')
content = urllib2.quote(content)
api_url = 'https://www.jb51.net/q=%s'%content
res = urllib2.urlopen(api_url)
希望本文所述对大家的Python程序设计有所帮助。
标签:python,urllib2,中文,方法
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
PHP getDocNamespaces()函数讲解
2023-06-13 22:19:06
![](https://img.aspxhome.com/file/2023/5/55405_0s.png)
浅谈Webpack多页应用HMR卡住问题
2023-07-20 01:27:12
![](https://img.aspxhome.com/file/2023/5/55925_0s.jpg)
asp 动态数组 提供Add、Insert、Remove、RemoveAt、Search等方法。
2011-03-17 11:10:00
PyTorch深度学习模型的保存和加载流程详解
2023-07-10 04:58:33
![](https://img.aspxhome.com/file/2023/4/63194_0s.png)
如何用ASP获知机器的网络配置?
2010-06-11 19:58:00
javascript用回车键实现Tab键功能
2009-07-05 18:40:00
Python中schedule模块定时任务的使用方法(2)
2023-09-01 09:59:59
Python给你的头像加上圣诞帽
2023-08-28 11:30:41
![](https://img.aspxhome.com/file/2023/5/92305_0s.jpg)
拿来就用!Python批量合并PDF的示例代码
2021-01-02 15:39:23
![](https://img.aspxhome.com/file/2023/7/78587_0s.jpg)
python中对开区间和闭区间的理解
2022-02-09 17:47:29
资料:MsSQL常用SQL语句
2009-02-23 12:54:00
sql如何删除数据库中数据记录
2008-10-09 12:31:00
利用Python自制网页并实现一键自动生成探索性数据分析报告
2023-01-19 13:20:12
![](https://img.aspxhome.com/file/2023/2/99172_0s.gif)
python 如何查看pytorch版本
2021-02-05 05:38:59
Python Panda中索引和选择 series 的数据
2023-05-03 10:02:56
![](https://img.aspxhome.com/file/2023/5/77865_0s.png)
QQ影音感念亲恩皮肤,不只是大按钮这么简单
2009-01-04 14:16:00
![](https://img.aspxhome.com/file/UploadPic/20091/4/0812_qqplayer_bigbutton_01-96s.jpg)
python Matplotlib数据可视化(2):详解三大容器对象与常用设置
2022-11-23 21:10:41
![](https://img.aspxhome.com/file/2023/2/70822_0s.png)
python中的插入排序的简单用法
2023-09-30 07:57:51
![](https://img.aspxhome.com/file/2023/3/63193_0s.png)
python安装pillow的三种方法
2023-07-20 02:36:53
![](https://img.aspxhome.com/file/2023/5/79495_0s.png)
[xhtml+css实例]不规则导航的制作
2008-04-04 18:11:00
![](https://img.aspxhome.com/file/UploadPic/20084/4/200844181914997s.jpg)