1.02-get-params
get params
2023-09-11 14:21:24 时间
import urllib.request import urllib.parse import string def get_method_params(): url = "http://www.baidu.com/s?wd=" #拼接字符串(汉字) #python可以接受的数据 #https://www.baidu.com/s?wd=%E7%BE%8E%E5%A5%B3 name = "美女" final_url = url+name print(final_url) #代码发送了请求 #网址里面包含了汉字;ascii是没有汉字的;url转译 #将包含汉字的网址进行转译 encode_new_url = urllib.parse.quote(final_url,safe=string.printable) print(encode_new_url) # 使用代码发送网络请求 response = urllib.request.urlopen(encode_new_url) print(response) #读取内容 data = response.read().decode() print(data) #保存到本地 with open("02-encode.html","w",encoding="utf-8")as f: f.write(data) #UnicodeEncodeError: 'ascii' codec can't encode # characters in position 10-11: ordinal not in range(128) #python:是解释性语言;解析器只支持 ascii 0 - 127 #不支持中文 get_method_params()
相关文章
- Http学习之使用HttpURLConnection发送post和get请求(1)
- How do I get a list of locally installed Python modules?
- What is the difference between POST and GET?
- Ubuntu通过apt-get安装指定版本和查询软件源有多少个版本
- xcode 真机调试 failed to get the task for process xxx
- Flutter移动电商实战 --(6)dio基础_Get_Post请求和动态组件协作
- mysql报ERROR:Deadlock found when trying to get lock; try restarting transaction(nodejs)
- 转 PHP函数---$_Get()和$_Post()的用法
- HttpClient_httpclient 4.3.1 post get的工具类
- 为什么重复的GET请求变慢了?
- [LeetCode] 1311. Get Watched Videos by Your Friends 获取你好友已观看的视频