python-对requests请求简单的封装
# coding:utf-8
import requests
class send_request:
def __init__(self,url,method,data=None):
self.response = self.run_main(url,method,data)
def send_get(self, url, data=None):
headers = {'content-type': 'charset=utf8'}
response = requests.get(url=url, data=data, headers=headers)
return response.content.decode('utf-8')
def send_post(self, url, data):
headers = {'content-type': 'charset=utf8'}
response = requests.post(url=url, data=data,headers=headers)
return response.content.decode('utf-8')
def run_main(self, url, method, data=None):
response = None
if method == 'get':
response = self.send_get(url, data)
elif method == 'post':
response = self.send_post(url, data)
else:
response = 'the method is error'
return response
if __name__ == '__main__':
url = 'https://www.baidu.com'
data = {
}
response = send_request(url=url, method='get')
print(response.response)
python-对requests请求简单的封装的更多相关文章
- python使用requests请求的数据乱码
1.首先进入目标网站,浏览器查看源码,找到head标签下面的meta标签,一般meta标签不止一个,我们只需找到charset属性里面的值即可 2.requests请求成功时,设置它的编码,代码如下 ...
- Python爬虫requests请求库
requests:pip install request 安装 实例: import requestsurl = 'http://www.baidu.com'response = requests. ...
- python 使用requests 请求 https 接口 ,取消警告waring
response = requests.request("POST", url, timeout=20, data=payload, headers=headers, proxie ...
- python用requests请求,报SSL:CERTIFICATE_VERIFY_FAILED错误。
response = requests.request("GET", url, headers=headers, params=querystring, verify=False) ...
- python发送requests请求时,使用登录的token值,作为下一个接口的请求头信息
背景介绍: 发送搜索请求时,需要用到登录接口返回值中的token值 代码实现: 登录代码: 搜索接口:
- python 用requests请求,报SSL:CERTIFICATE_VERIFY_FAILED错误
https://www.aliyun.com/jiaocheng/437481.html
- requests请求获取cookies的字典格式
python中requests请求的cookies值一般是jar包,如何将cookies值改为字典,此处运用了方法.举例如下: import requests response = requests ...
- Python+requests 发送简单请求--》获取响应状态--》获取请求响应数据
Python+requests 发送简单请求-->获取响应状态-->获取请求响应数据 1.环境:安装了Python和vscode编译器(Python自带的编译器也ok).fiddler抓包 ...
- python爬虫#网络请求requests库
中文文档 http://docs.python-requests.org/zh_CN/latest/user/quickstart.html requests库 虽然Python的标准库中 urlli ...
随机推荐
- Github排序(转载)
目录 1. 冒泡排序 2. 选择排序 3. 插入排序 4. 希尔排序 5. 归并排序 6. 快速排序 7. 堆排序 8. 计数排序 9. 桶排序 10. 基数排序 参考:https://mp.weix ...
- MongoDB十二种最有效的模式设计【转】
持续关注MongoDB博客(https://www.mongodb.com/blog)的同学一定会留意到,技术大牛Daniel Coupal 和 Ken W. Alger ,从 今年 2月17 号开始 ...
- c/c++ 动态库与静态库的制作和使用
静态库的用法 静态库的文件名 libxxx.a -->对应windows的.lib文件 做静态库的命令: ar rcs libxxx.a file1.o file2.o file.o 使用静态库 ...
- Scala实现Try with resources自动关闭IO
在处理数据库连接或者输入输出流等场景时,我们经常需要写一些非常繁琐又枯燥乏味的代码来关闭数据库连接或输入输出流. 例如数据库操作: def update(sql: String)(conn: Conn ...
- C# 定时关机小程序
1.打开VS2019,创建界面和按钮 2. 代码如下: private void button1_Click(object sender, EventArgs e) { downpc(txttime. ...
- Vue+abp微信扫码登录
最近系统中要使用微信扫码登录,根据微信官方文档和网络搜索相关文献实现了.分享给需要的人,也作为自己的一个笔记.后端系统是基于ABP的,所以部分代码直接使用了abp的接口,直接拷贝代码编译不通过. 注册 ...
- jquery mobile 建wap站
使用jquery mobile 建手机wap站: 几篇比较好的文章 http://wap.yesky.com/dev/225/30974725.shtml http://tech.it168.com/ ...
- Python基础(os模块)
os模块用于操作系统级别的操作: os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录:相当 ...
- Python基础(数字,字符串方法)
数字: #二进制转十进制 a=' v=int(a,base=2) print(v) 进制转换 #当前数字的二进制至少有多少位 b=2 v2=b.bit_length() print(v2) 数值二进制 ...
- SQL Server的case when用法
1.简单sql一例 SELECT top 10 CASE WHEN IDENTITY_ID='1' THEN '管理员' WHEN IDENTITY_ID='5' THEN '学生' ELSE '无' ...