python3: requests模块的使用;
requests库常用于http请求,可以很方便对网页进行爬取;
主要方法(七个):
| 方法 | 解释 |
|---|---|
| requests.request() | 构造一个请求,支持以下各种方法 |
| requests.get() | 获取html的主要方法 |
| requests.head() | 获取html头部信息的主要方法 |
| requests.post() | 向html网页提交post请求的方法 |
| requests.put() | 向html网页提交put请求的方法 |
| requests.patch() | 向html提交局部修改的请求 |
| requests.delete() | 向html提交删除请求 |
1.requests.get
原型:
r = requests.get(url,params, **kwargs)
url: 网站地址;
params: 参数, 额外参数,可以使字典或者字节流
**kwargs: 12个控制访问的参数( 这里不讲述);
响应response对象有以下属性:
| 属性 | 说明 |
|---|---|
| r.status_code | http请求的返回状态,若为200则表示请求成功。 |
| r.text | http响应内容的字符串形式,即返回的页面内容 |
| r.encoding | 从http header 中猜测的相应内容编码方式 |
| r.apparent_encoding | 从内容中分析出的响应内容编码方式(备选编码方式) |
| r.content | http响应内容的二进制形式 |
其他略(请见: https://blog.csdn.net/gyq1998/article/details/78583841)
python3: requests模块的使用;的更多相关文章
- python3 requests模块
一.Requests用法: 1.发送请求: 1).请求类型:req_obj = requests.get("https://www.baidu.com")requests支持多种请 ...
- python3:requests模块-写了一点
使用requests,它的七个主要方法,在这里只讲两个:get.post >>> import requests >>> r=requests.get(" ...
- python3 requests模块 基本操作
import requests import json # 1.HTTP方法 requests.get('https://github.com/timeline.json') #GET请求 reque ...
- python3 requests 模块 json参数和data参数区别
json 表示使用application/json方式提交请求 data 使用application/form-urlencode方式提交请求
- [实战演练]python3使用requests模块爬取页面内容
本文摘要: 1.安装pip 2.安装requests模块 3.安装beautifulsoup4 4.requests模块浅析 + 发送请求 + 传递URL参数 + 响应内容 + 获取网页编码 + 获取 ...
- python3使用requests模块完成get/post/代理/自定义header/自定义Cookie
一.背景说明 http请求的难易对一门语言来说是很重要的而且是越来越重要,但对于python一是urllib一些写法不太符合人的思维习惯文档也相当难看,二是在python2.x和python3.x中写 ...
- Python3:Requests模块的异常值处理
Python3:Requests模块的异常值处理 用Python的requests模块进行爬虫时,一个简单高效的模块就是requests模块,利用get()或者post()函数,发送请求. 但是在真正 ...
- (转)Python3之requests模块
原文:https://www.cnblogs.com/wang-yc/p/5623711.html Python标准库中提供了:urllib等模块以供Http请求,但是,它的 API 太渣了.它是为另 ...
- Python3之requests模块
Python标准库中提供了:urllib等模块以供Http请求,但是,它的 API 太渣了.它是为另一个时代.另一个互联网所创建的.它需要巨量的工作,甚至包括各种方法覆盖,来完成最简单的任务. 发送G ...
随机推荐
- How to goproxy
brew install python python "/users/cuthead/desktop/phuslu-goproxy-9087f35/uploader.py" sel ...
- mybatis,主键返回指的是返回到传入的对象中
- kubernetes 基本命令
查询命令: kubectl get pods -n kube-system kubectl get ClusterRole -n kube-system kubectl get ClusterRole ...
- java excel Workbook API
此文摘自:http://blog.sina.com.cn/zenyunhai 1. int getNumberOfSheets() 获得工作薄(Workbook)中工作表(Sheet)的个数,示例: ...
- Codeforces Round #415 Div. 1
A:考虑每对最大值最小值的贡献即可. #include<iostream> #include<cstdio> #include<cmath> #include< ...
- 【XSY1580】Y队列 容斥
题目大意 给你\(n,r\),求第\(n\)个不能被表示为\(a^b(2\leq b\leq r)\)的数 \(n\leq 2\times {10}^{18},r\leq 62\) 题解 我们考虑二分 ...
- github Permission denied (publickey). fatal: Could not read from remote repository.
github Permission denied (publickey).fatal: Could not read from remote repository. ----------------- ...
- table用模板生成的问题
在使用<template></template>存放HTML模板标记时,发现一个烦人的问题,表格不行. <template> <table> <t ...
- [SHOI2001]化工厂装箱员(dp?暴力:暴力)
118号工厂是世界唯一秘密提炼锎的化工厂,由于提炼锎的难度非常高,技术不是十分完善,所以工厂生产的锎成品可能会有3种不同的纯度,A:100%,B:1%,C:0.01%,为了出售方便,必须把不同纯度 ...
- 解决mysql配置文件my.cnf添加max_connections不生效
问题描述: 最新为了方便测试,通过mysql官方指定的yum源安装了mysql5.6.40,在向mysql的配置文件my.cnf添加max_connections=3600后,重启mysql后发现不生 ...