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 ...
随机推荐
- 入门rocketmq从浅到深
目录 一.引言 二.介绍 三.Rocketmq关键概念 1.主题与标签 2.发送与订阅群组 3.Broker与NameServer 4.广播消费与集群消费 5.消息队列 6.集群方式 7.顺序消息 8 ...
- vue中路由按需加载的几种方式
使用vue-cli构建项目后,我们会在Router文件夹下面的index.js里面引入相关的路由组件,如: import Hello from '@/components/Hello' import ...
- 联发科MT8788基带处理器介绍
MT8788设备具有集成的蓝牙.fm.wlan和gps模块,是一个高度集成的基带平台,包括调制解调器和应用处理子系统,启用LTE/LTE-A和C2K智能设备应用程序.该芯片集成了工作在2.0GHz的A ...
- Windows server 1709(不含UI)模板部署
1.系统安装 在虚拟机导入安装镜像,客户端操作系统选择” windows server 2012”,虚拟磁盘类型选择”SCSI”:依照安装向导正确安装操作系统 2.安装vmware tools 选择虚 ...
- #ifndef, #define, #endif 作用
#ifndef, #define, #endif 作用 https://www.cnblogs.com/challenger-vip/p/3386819.html
- ASP.NET Core 共享第三方依赖库部署的正常打开方式
曾经: 写了一篇: ASP.Net Core on Linux (CentOS7) 共享第三方依赖库部署 当第二次想做相同的事,却遇上了Bug,于是有了第二篇: ASP.NET Core 共享第三方依 ...
- PHP全栈学习笔记17
phpmyadmin教程 管理页进入phpmyadmin 打开C:\wamp\apps\phpmyadmin3.5.1下的配置文件:config.inc 修改密码 创建与修改数据库.数据表 字段类型 ...
- CSS揭秘—灵活的背景图(三)
前言: 所有实例均来自<CSS揭秘>,该书以平时遇到的疑难杂症为引,提供解决方法,只能说秒极了,再一次刷新了我对CSS的认知 该书只提供了关键CSS代码,虽然有在线示例代码链接,但访问速度 ...
- 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之五 || Swagger的使用 3.3 JWT权限验证【必看】
前言 关于JWT一共三篇 姊妹篇,内容分别从简单到复杂,一定要多看多想: 一.Swagger的使用 3.3 JWT权限验证[修改] 二.解决JWT权限验证过期问题 三.JWT完美实现权限与接口的动态分 ...
- mybatis自动填充时间字段
对于实体中的created_on和updated_on来说,它没有必要被开发人员去干预,因为它已经足够说明使用场景了,即在插入数据和更新数据时,记录当前时间,这对于mybatis来说,通过拦截器是可以 ...