首页
学习
活动
专区
圈层
工具
发布
综合排序最热优先最新优先
时间不限
Requests
库的异常 异常 说明 requests.ConnectionError 网络连接错误异常,如DNS查询失败、拒绝连接等 requests.HTTPErro HTTP错误异常 requests.URLRequired URL缺失异常 requests.TooManyRedirects 超过最大重定向次数,产生重定向异常 requests.ConnectTimeout 连接远程服务器超时异常 requests.Timeout 与协议方法一一对应 方法 介绍 requests.request() 设置请求格式 requests.get() 请求获取url位置的资源 requests.head() 请求获取url位置的资源的响应报告 ,及获得头部信息 requests.post() 请求获取url位置的资源后附加用户新的数据 requests.put() 请求获取url位置储存一个资源,覆盖原url位置资源 requests.patch () 请求局部更新url位置资源,及改变该处资源的部分内容 requests.delete() 请求删除url位置储存的资源 4.Requests库13个参数 params:字典或字节序列,作为参数增加到链接中
小小咸鱼YwY
2019-07-24
8550
标签:
python requests
问题: requests.exceptions.InvalidHeader: Value for header {Upgrade-Insecure-Requests: 1} must be of type
hankleo
2020-09-16
1K0
标签:
requests 扩展 | Requests-Cache(爬虫缓存)
同样地,当使用requests模块向一个URL发送重复请求时,也需要判断当前网络是否产生了缓存。此时Requests-Cache模块将会自动判断,若产生了缓存,则会读取数据作为响应内容。 >>> # 安装Requests-Cache模块 >>> pip install requests-cache >>> # 检查模块是否安装成功 >>> import requests_cache >> > requests_cache. ---- 应用 >>> import requests_cache >>> import requests >>> requests_cache.install_cache() # 设置缓存 >>> import requests_cache import time requests_cache.install_cache() requests_cache.clear() def make_throttle_hook
数据STUDIO
2021-06-24
2.3K0
标签:
python requests
requests会自动实现持久连接keep-alive 2、基础入门 1)导入模块 import requests 2)发送请求的简洁   示例代码:获取一个网页(个人github) import requests post类型 r = requests.post("http://m.ctrip.com/post") # put类型 r = requests.put("http://m.ctrip.com/put requests from requests.auth import HTTPBasicAuth r = requests.get('https://httpbin.org/hidden-basic-auth 模块抓取网页源码并保存到文件示例 这是一个基本的文件保存操作,但这里有几个值得注意的问题: 1.安装requests包,命令行输入pip install requests即可自动安装。 /urs/bin/python3 import requests '''requests模块抓取网页源码并保存到文件示例''' html = requests.get("http://www.baidu.com
forxtz
2022-05-10
2.1K0
标签:
requests时报错requests.exceptions.SSLError: HTTPSConnectionPool
报错信息 raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='www.baidu.com 安装一下几个requests依赖包,然后设置, verify=False pip install cryptography pip install pyOpenSSL pip install certifi >>> response = requests.get('http://www.baidu.com/', headers = header, verify=False) D:\python\lib\site-packages readthedocs.io/en/latest/advanced-usage.html#ssl-warnings InsecureRequestWarning) 想去掉红框内的内容还需要添加如下代码 requests.packages.urllib3
周小董
2020-01-13
6.9K0
标签:
Requests
库的异常 异常 说明 requests.ConnectionError 网络连接错误异常,如DNS查询失败、拒绝连接等 requests.HTTPErro HTTP错误异常 requests.URLRequired URL缺失异常 requests.TooManyRedirects 超过最大重定向次数,产生重定向异常 requests.ConnectTimeout 连接远程服务器超时异常 requests.Timeout 与协议方法一一对应 方法 介绍 requests.request() 设置请求格式 requests.get() 请求获取url位置的资源 requests.head () 请求获取url位置的资源的响应报告,及获得头部信息 requests.post() 请求获取url位置的资源后附加用户新的数据 requests.put() 请求获取url位置储存一个资源,覆盖原 url位置资源 requests.patch() 请求局部更新url位置资源,及改变该处资源的部分内容 requests.delete() 请求删除url位置储存的资源 4.Requests库13个参数
小小咸鱼YwY
2020-01-17
9290
标签:
Requests爬虫
1 import requests 2 3 r = requests.get("https://www.icourse163.org/home.htm? 1 import requests 2 from requests.exceptions import ReadTimeout, ConnectionError, RequestException 1 import requests 2 3 def getHtmlText(url): 4 try: 5 r = requests.get(url) 6 1 import requests 2 url = "https://item.jd.com/8578888.html" 3 try: 4 r = requests.get(url) 5 1 import requests 2 3 response = requests.get("https://www.baidu.com") 4 print(response.cookies) #
py3study
2020-01-19
7980
标签:
requests
import requests headers={ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ,则有 kw={"wd":"中国"} url="https://www.baidu.com/s" #将kw用params传递到url中,通过get请求 response=requests.get(url response.encoding(response的编码方式) utf-8 response.status_code(HTTP请求状态码,200表示请求成功) 2.处理post请求 response=requests.post (url,headers=headers,data=data) print(response.json()) 3.使用代理 resp=requests.get(url,headers=headers,proxies 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36', } session=requests.session
西西嘛呦
2020-08-26
5580
标签:
python爬虫 requests异常:requests.exceptions.ConnectionError...
使用 requests抓取网页时会碰到如下异常: requests.exceptions.ConnectionError: HTTPSConnectionPool Max retries exceeded 2.ip被封 3.请求过快 解决 1.在header中不使用持久连接‘Connection’: ‘close’或requests.adapters.DEFAULT_RETRIES = 5 2.若是请求过快 ,可设置time.sleep 3.使用代理ip 4.Requests请求时有时会请求不到页面,或是请求到空白的页面,超时要重试几次,使用try…except语句
周小董
2019-06-24
11.7K0
标签:
requests 扩展 | Requests-HTML(增强版)
Requests-HTML模块 Requests-HTML模块与requests模块为同一开发者所开发。是requests模块的增强版。 >>> # 安装Requests-HTML模块 >>> pip install requests-html >>> # 检查模块是否安装成功 >>> import requests_html >>> requests_cache 请求头信息 前面已经介绍了,Requests-HTML模块会模拟真实浏览器向URL发送网络请求,虽然Requests-HTML模块已经设置了默认的请求头"User-Agent"信息,必要时可以对其进行修改 print(res.text) 数据提取 Requests-HTML模块直接提供了支持CSS选择器及XPath的节点提取方式。而requests需要配合HTML解析器。 Requests-HTML模块提供了render()方法来解决此类问题。 ?
数据STUDIO
2021-06-24
3.7K0
标签:
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档