iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python中requests库怎么使用
  • 840
分享到

Python中requests库怎么使用

2023-06-30 18:06:32 840人浏览 泡泡鱼

Python 官方文档:入门教程 => 点击学习

摘要

这篇文章主要介绍了python中requests库怎么使用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Python中requests库怎么使用文章都会有所收获,下面我们一起来看看吧。一、requests库re

这篇文章主要介绍了python中requests库怎么使用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Python中requests库怎么使用文章都会有所收获,下面我们一起来看看吧。

一、requests库

requests是使用Apache2 licensed 许可证的Http库。比urllib模块更简洁。

Request支持HTTP连接保持和连接池,支持使用cookie保持会话,支持文件上传,支持自动响应内容的编码,支持国际化的URL和POST数据自动编码。

在python内置模块的基础上进行了高度的封装,从而使得python进行网络请求时,变得人性化,使用Requests可以轻而易举的完成浏览器可有的任何操作。

安装

requests是第三方库,需要独立安装:pip install requests。requests是基于urllib编写的,并且使用起来非常方便,个人推荐使用requests。

请求

requests支持http的各种请求,比如:

  • GET: 请求指定的页面信息,并返回实体主体。

  • HEAD: 只请求页面的首部。

  • POST: 请求服务器接受所指定的文档作为对所标识的URI的新的从属实体。

  • PUT: 从客户端向服务器传送的数据取代指定的文档的内容。

  • DELETE: 请求服务器删除指定的页面。

  • OPTIONS: 允许客户端查看服务器的性能。

访问baidu,获取一些基本信息:

import requestsresponse = requests.get("https://www.baidu.com")# 打开网页获取响应print('response:', type(response))# 打印响应类型,response: print('status_code:', response.status_code)# 打印状态码 ,status_code: 200print('cookie:', response.cookies)#  打印cookie  ,cookie: ]></requestscookiejar[print(type(response.text)) # 打印字符串形式的JSON响应体的类型 ,< class 'str'>print('text:', response.text)   # 打印字符串形式的响应体 ,text: >ç™»å½...•print('二进制content:', response.content)       # 二进制content, b'\r\n\xe7\x99\xbb\xe5\xbd\x95... \r\n'print('content:', response.content.decode("utf-8")) # content:  登录...

响应

请求后响应的内容是requests.models.Response对象,需要处理后才能得到我们需要的信息。

requests自动检测编码,可以使用encoding属性查看。

无论响应是文本还是二进制内容,我们都可以用content属性获得bytes对象:

  • encoding:获取当前的编码

  • encoding = 'utf-8' :设置编码

  • headers :以字典对象存储服务器响应头,但是这个字典比较特殊,字典键不区分大小写,若键不存在则返回None

  • requests.headers :返回发送到服务器的头信息

  • cookies :返回cookie

  • history :返回重定向信息,当然可以在请求是加上allow_redirects = false 阻止重定向

  • status_code :响应状态码

  • raw :返回原始响应体,也就是 urllib 的 response 对象,使用 r.raw.read()

  • ok :查看r.ok的布尔值便可以知道是否登陆成功

  • raise_for_status() :失败请求(非200响应)抛出异常

  • text: 得到的是str类型,会自动根据响应头部的字符编码进行解码。

  • content :得到的是bytes类型,需要进行解码Response_get.content.decode(),相当于Response_get.text。字节方式的响应体,会自动为你解码 gzip 和 deflate 压缩。

  • json(): Requests中内置的jsON解码器,以json形式返回,前提返回的内容确保是json格式的,不然解析出错会抛异常

其实使用requset.text避免乱码的方式还有一个,就是发出请求后,获取内容之前使用response.encoding属性来改变编码,例如:

response =requests.get("http://www.baidu.com") #设置响应内容的编码方式为utf-8response.encoding="utf-8"print(response.text)

二、发送get请求

requests.get(url=url, headers=headers, params=params)
  • url:请求url地址

  • headers:请求头

  • params:查询字符串

1、一个带参数的get请求:

对于带参数的URL,传入一个dict作为params参数,如果值为None的键不会被添加到url中。

import requests    #将参数写在字典里,通过params传入,params接受字典或序列    data = {        "name": "hanson",        "age": 24    }   response = requests.get("http://httpbin.org/get", params=data) #发出一个get请求,获得响应   print(response.url) #打印url   print(response.text) #打印响应内容

结果为:

http://httpbin.org/get?name=hanson&age=24{   "args": {     "age": "24",      "name": "hanson"   },    "headers": {     "Accept": "**', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}, 'origin': '124.74.47.82', 'url': 'http://httpbin.org/get'} {'args': {}, 'headers': {'Accept': '**",      "Accept-Encoding": "gzip, deflate",      "Content-Length": "19",      "Content-Type": "application/x-www-fORM-urlencoded",      "Host": "httpbin.org",      "User-Agent": "python-requests/2.18.4"   },    "json": null,    "origin": "124.74.47.82, 124.74.47.82",    "url": "https://httpbin.org/post" }

2、传递JSON数据

requests默认使用application/x-www-form-urlencoded对POST数据编码。如果要传递JSON数据,可以直接传入json参数:

params = {'key': 'value'}r = requests.post(url, json=params) # 内部自动序列化为JSON

3、文件上传

文件上传需要用到请求参数里的files参数:

在读取文件时,注意务必使用'rb'即二进制模式读取,这样获取的bytes长度才是文件的长度。

import requests# rb,以只读的方式打开二进制文件files = {"files": open("a.jpg", "rb")}# 发送post请求携带文件response = requests.post("http://httpbin.org/post", files=files)# 响应内容print(response.text)

响应结果:

{   "args": {},    "data": "",    "files": {     "files": ""   },    "form": {},    "headers": {     "Accept": "**;q=0.8',           'Accept-Encoding': 'gzip, deflate, compress',           'Accept-Language': 'en-us;q=0.5,en;q=0.3',           'Cache-Control': 'max-age=0',           'Connection': 'keep-alive',           'User-Agent': 'Mozilla/5.0 (X11; ubuntulinux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0'}       #创建session对象    s = requests.Session()    s.headers.update(headers)#使用session访问并设置number参数    s.get("http://httpbin.org/cookies/set/number/123456")    #session对象再次访问,获取响应内容    response = s.get("http://httpbin.org/cookies")    print(response.text)

2、身份验证

auth:认证,接受元祖

基本身份认证(HTTP Basic Auth)

import requestsfrom requests.auth import HTTPBasicAuth r = requests.get('https://httpbin.org/hidden-basic-auth/user/passwd', auth=HTTPBasicAuth('user', 'passwd'))print(r.json())

简写:

response = requests.get("http://120.27.34.24:9001/",auth=("user","123"))

另一种非常流行的HTTP身份认证形式是摘要式身份认证,Requests对它的支持也是开箱即可用的:

requests.get(URL, auth=HTTPDigestAuth('user', 'pass')

3、代理设置

proxies = {'http':'ip1','https':'ip2' }requests.get('url',proxies=proxies)

如果代理需要用户名和密码,则需要这样:

proxies = {    "http": "http://user:pass@10.10.1.10:3128/",}

4、证书验证

现在的很多网站都是https的方式访问,所以这个时候就涉及到证书的问题

例如访问12306:

import requestsresponse = requests.get("https:/www.12306.cn")print(response.status_code)

会报错,证书错误

解决:加上verify=false(默认是true)

import requests     #from requests.packages import urllib3     #urllib3.disable_warnings()     response = requests.get("https://www.12306.cn", verify=False)     print(response.status_code)

5、超时时间

timeout,单位:毫秒

r = requests.get('url',timeout=1)           #设置秒数超时,仅对于连接有效

6、重定向与请求历史

使用GET或OPTIONS时,Requests会自动处理位置重定向。

GitHub将所有的HTTP请求重定向到HTTPS。可以使用响应对象的 history 方法来追踪重定向。 我们来看看github做了什么:

r = requests.get('http://github.com')>>> r.url'https://github.com/'>>> r.status_code200>>> r.history[]

Response.history 是一个:class:Request 对象的列表,为了完成请求而创建了这些对象。这个对象列表按照从最老到最近的请求进行排序

如果你使用的是GET或OPTIONS,那么你可以通过 allow_redirects 参数禁用重定向处理:

r = requests.get('http://github.com', allow_redirects=False)>>> r.status_code301>>> r.history[]

7、其他

  • stream:是否下载获取的内容

  • cert:保存本地SSL证书路径

五、异常处理

所有的异常都是在requests.excepitons中:

示例:

import requests   from requests.exceptions import ReadTimeout,ConnectionError,RequestException  try:     response = requests.get("http://httpbin.org/get",timout=0.1)     print(response.status_code) except ReadTimeout:     print("timeout") except ConnectionError:     print("connection Error") except RequestException:     print("error")

测试可以发现,首先被捕捉的异常是timeout超时异常,当把网络断掉就会捕捉到ConnectionError连接异常,如果前面异常都没有捕捉到,最后也可以通过RequestExctption捕捉到。

六、requests库和urllib包对比

1、使用urllib.request

import urllib.parseimport urllib.requesturl = "https://api.douban.com/v2/event/list"params = urllib.parse.urlencode({'loc':'108288','day_type':'weekend','type':'exhibition'})print(">>>>>>request params is:")print(params) # 发送请求response = urllib.request.urlopen('?'.join([url, params])) # 处理响应print(">>>>>>Response Headers:")print(dict(response.info()))print(">>>>>>Status Code:")print(response.getcode())print(">>>>>>Response body:")print(response.read().decode())

2、使用requests库

import requestsurl = "https://api.douban.com/v2/event/list"params = {'loc':'108288','day_type':'weekend','type':'exhibition'}print(">>>>>>request params is:")print(params)# 发送请求response = requests.get(url=url,params=params)# 处理响应print(">>>>>>Response Headers:")print(response.headers)print(">>>>>>Status Code:")print(response.status_code)print(">>>>>>Response body:")print(response.text)

3、区别:

  • 构建参数:在构建请求参数时,第一种需要将请求参数使用urllib库的urlencode方法进行编码预处理,非常麻烦。

  • 请求方法:发送get请求时,第一种使用的urllib库的urlopen方法打开一个url地址,而第二种直接使用requests库的get方法,与http请求方式是对应的,更加直接、易懂。

  • 请求数据:第一种按照url格式去拼接一个url字符串,显然非常麻烦,第二种按顺序将get请求的url和参数写好就可以了。

  • 处理响应:第一种处理消息头部、响应状态码和响应正文时分别使用.info()、.getcode()、.read()方法,第二种使用.headers、.status_code、.text方法,方法名称与功能本身相对应,更方便理解、学习和使用。

  • 连接方式:看一下返回数据的头信息的“connection”,使用urllib库时,“connection”:“close”,说明每次请求结束关掉Socket通道,而使用requests库使用了urllib3,多次请求重复使用一个socket,“connection”:“keep-alive”,说明多次请求使用一个连接,消耗更少的资源。

  • 编码方式:requests库的编码方式Accept-Encoding更全。

七、自动登陆"示例:

1、抽屉新热榜

#!/usr/bin/env python# -*- coding:utf-8 -*-import requests# ############## 方式一 ##############"""# ## 1、首先登陆任何页面,获取cookiei1 = requests.get(url="http://dig.chouti.com/help/service")i1_cookies = i1.cookies.get_dict()# ## 2、用户登陆,携带上一次的cookie,后台对cookie中的 gpsd 进行授权i2 = requests.post(    url="http://dig.chouti.com/login",    data={        'phone': "8615131255089",        'passWord': "xxooxxoo",        'oneMonth': ""    },    cookies=i1_cookies)# ## 3、点赞(只需要携带已经被授权的gpsd即可)gpsd = i1_cookies['gpsd']i3 = requests.post(    url="http://dig.chouti.com/link/vote?linksId=8589523",    cookies={'gpsd': gpsd})print(i3.text)"""# ############## 方式二 ##############"""import requestssession = requests.Session()i1 = session.get(url="http://dig.chouti.com/help/service")i2 = session.post(    url="http://dig.chouti.com/login",    data={        'phone': "8615131255089",        'password': "xxooxxoo",        'oneMonth': ""    })i3 = session.post(    url="http://dig.chouti.com/link/vote?linksId=8589523")print(i3.text)"""

2、 github

#!/usr/bin/env python# -*- coding:utf-8 -*-import requestsfrom bs4 import BeautifulSoup# ############## 方式一 ################ # 1. 访问登陆页面,获取 authenticity_token# i1 = requests.get('https://github.com/login')# soup1 = BeautifulSoup(i1.text, features='lxml')# tag = soup1.find(name='input', attrs={'name': 'authenticity_token'})# authenticity_token = tag.get('value')# c1 = i1.cookies.get_dict()# i1.close()## # 1. 携带authenticity_token和用户名密码等信息,发送用户验证# form_data = {# "authenticity_token": authenticity_token,#     "utf8": "",#     "commit": "Sign in",#     "login": "wupeiqi@live.com",#     'password': 'xxoo'# }## i2 = requests.post('https://github.com/session', data=form_data, cookies=c1)# c2 = i2.cookies.get_dict()# c1.update(c2)# i3 = requests.get('https://github.com/settings/repositories', cookies=c1)## soup3 = BeautifulSoup(i3.text, features='lxml')# list_group = soup3.find(name='div', class_='listgroup')## from bs4.element import Tag## for child in list_group.children:#     if isinstance(child, Tag):#         project_tag = child.find(name='a', class_='mr-1')#         size_tag = child.find(name='small')#         temp = "项目:%s(%s); 项目路径:%s" % (project_tag.get('href'), size_tag.string, project_tag.string, )#         print(temp)# ############## 方式二 ############### session = requests.Session()# # 1. 访问登陆页面,获取 authenticity_token# i1 = session.get('https://github.com/login')# soup1 = BeautifulSoup(i1.text, features='lxml')# tag = soup1.find(name='input', attrs={'name': 'authenticity_token'})# authenticity_token = tag.get('value')# c1 = i1.cookies.get_dict()# i1.close()## # 1. 携带authenticity_token和用户名密码等信息,发送用户验证# form_data = {#     "authenticity_token": authenticity_token,#     "utf8": "",#     "commit": "Sign in",#     "login": "wupeiqi@live.com",#     'password': 'xxoo'# }## i2 = session.post('https://github.com/session', data=form_data)# c2 = i2.cookies.get_dict()# c1.update(c2)# i3 = session.get('https://github.com/settings/repositories')## soup3 = BeautifulSoup(i3.text, features='lxml')# list_group = soup3.find(name='div', class_='listgroup')## from bs4.element import Tag## for child in list_group.children:#     if isinstance(child, Tag):#         project_tag = child.find(name='a', class_='mr-1')#         size_tag = child.find(name='small')#         temp = "项目:%s(%s); 项目路径:%s" % (project_tag.get('href'), size_tag.string, project_tag.string, )#         print(temp)

3、 知乎

#!/usr/bin/env python# -*- coding:utf-8 -*-import timeimport requestsfrom bs4 import BeautifulSoupsession = requests.Session()i1 = session.get(    url='https://www.zhihu.com/#signin',    headers={        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWEBKit/537.36 (Khtml, like Gecko) Chrome/54.0.2840.98 Safari/537.36',    })soup1 = BeautifulSoup(i1.text, 'lxml')xsrf_tag = soup1.find(name='input', attrs={'name': '_xsrf'})xsrf = xsrf_tag.get('value')current_time = time.time()i2 = session.get(    url='https://file.lsjlt.com/upload/202306/28/w1rzodwfkvs.gif',    params={'r': current_time, 'type': 'login'},    headers={        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36',    })with open('zhihu.gif', 'wb') as f:    f.write(i2.content)captcha = input('请打开zhihu.gif文件,查看并输入验证码:')form_data = {    "_xsrf": xsrf,    'password': 'xxooxxoo',    "captcha": 'captcha',    'email': '424662508@qq.com'}i3 = session.post(    url='https://www.zhihu.com/login/email',    data=form_data,    headers={        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36',    })i4 = session.get(    url='https://www.zhihu.com/settings/profile',    headers={        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36',    })soup4 = BeautifulSoup(i4.text, 'lxml')tag = soup4.find(id='rename-section')nick_name = tag.find('span',class_='name').stringprint(nick_name)

4、 博客园

#!/usr/bin/env python# -*- coding:utf-8 -*-import reimport jsonimport base64import rsaimport requestsdef js_encrypt(text):    b64der = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp0wHYbg/NOPO3nzMD3dndwS0MccuMeXCHgVlGooYyFwLdS24Im2e7YyhB0wrUsyYf0/nhzCzBK8ZC9eCWqd0aHbdgOQt6CuFQBMjbyGYvlVYU2ZP7kG9Ft6YV6oc9ambuO7nPZh+bvXH0zDKfi02prknrScAKC0XhadTHT3Al0QIDAQAB'    der = base64.standard_b64decode(b64der)    pk = rsa.PublicKey.load_pkcs1_openssl_der(der)    v1 = rsa.encrypt(bytes(text, 'utf8'), pk)    value = base64.encodebytes(v1).replace(b'\n', b'')    value = value.decode('utf8')    return valuesession = requests.Session()i1 = session.get('https://passport.cnblogs.com/user/signin')rep = re.compile("'VerificationToken': '(.*)'")v = re.search(rep, i1.text)verification_token = v.group(1)form_data = {    'input1': js_encrypt('wptawy'),    'input2': js_encrypt('asdfasdf'),    'remember': False}i2 = session.post(url='https://passport.cnblogs.com/user/signin',                  data=json.dumps(form_data),                  headers={                      'Content-Type': 'application/json; charset=UTF-8',                      'X-Requested-With': 'XMLHttpRequest',                      'VerificationToken': verification_token}                  )i3 = session.get(url='https://i.cnblogs.com/EditDiary.aspx')print(i3.text)

5、 拉勾网

#!/usr/bin/env python# -*- coding:utf-8 -*-import requests# 第一步:访问登陆页,拿到X_Anti_Forge_Token,X_Anti_Forge_Code# 1、请求url:https://passport.lagou.com/login/login.html# 2、请求方法:GET# 3、请求头:#    User-agentr1 = requests.get('https://passport.lagou.com/login/login.html',                 headers={                     'User-Agent': 'Mozilla/5.0 (windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',                 },                 )X_Anti_Forge_Token = re.findall("X_Anti_Forge_Token = '(.*?)'", r1.text, re.S)[0]X_Anti_Forge_Code = re.findall("X_Anti_Forge_Code = '(.*?)'", r1.text, re.S)[0]print(X_Anti_Forge_Token, X_Anti_Forge_Code)# print(r1.cookies.get_dict())# 第二步:登陆# 1、请求url:https://passport.lagou.com/login/login.json# 2、请求方法:POST# 3、请求头:#    cookie#    User-agent#    Referer:https://passport.lagou.com/login/login.html#    X-Anit-Forge-Code:53165984#    X-Anit-Forge-Token:3b6a2f62-80f0-428b-8efb-ef72fc100d78#    X-Requested-With:XMLHttpRequest# 4、请求体:# isValidate:true# username:15131252215# password:ab18d270d7126ea65915c50288c22c0d# request_form_verifyCode:''# submit:''r2 = requests.post(    'https://passport.lagou.com/login/login.json',    headers={        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',        'Referer': 'https://passport.lagou.com/login/login.html',        'X-Anit-Forge-Code': X_Anti_Forge_Code,        'X-Anit-Forge-Token': X_Anti_Forge_Token,        'X-Requested-With': 'XMLHttpRequest'    },    data={        "isValidate": True,        'username': '15131255089',        'password': 'ab18d270d7126ea65915c50288c22c0d',        'request_form_verifyCode': '',        'submit': ''    },    cookies=r1.cookies.get_dict())print(r2.text)

关于“Python中requests库怎么使用”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“Python中requests库怎么使用”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注编程网Python频道。

--结束END--

本文标题: Python中requests库怎么使用

本文链接: https://www.lsjlt.com/news/330790.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Python中requests库怎么使用
    这篇文章主要介绍了Python中requests库怎么使用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Python中requests库怎么使用文章都会有所收获,下面我们一起来看看吧。一、requests库re...
    99+
    2023-06-30
  • python爬虫中requests库怎么用
    小编给大家分享一下python爬虫中requests库怎么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!python爬虫—requests库的用法request...
    99+
    2023-06-25
  • Python中requests库
    文章目录 requests库一、 基本概念1、 简介2、 获取3、 http 协议3.1 URL3.2 常用 http 请求方法 二、 使用方法1、 基本语法requests 库...
    99+
    2023-09-07
    python http 开发语言
  • Python网络爬虫requests库怎么使用
    1. 什么是网络爬虫简单来说,就是构建一个程序,以自动化的方式从网络上下载、解析和组织数据。就像我们浏览网页的时候,对于我们感兴趣的内容我们会复制粘贴到自己的笔记本中,方便下次阅读浏览&mdash;&mdash;网络爬虫帮我...
    99+
    2023-05-15
    Python Requests
  • python中requests库+xpath+lxml简单使用
    目录安装简单使用1.简单访问一个url:2.带参数访问url4.requests的一些常用方法和主要参数5.requests.Response对象的属性说明xpath简介lxml简介...
    99+
    2024-04-02
  • python中requests库安装与使用详解
    目录前言1、Requests介绍2、requests库的安装3、requests库常用的方法4、response对象的常用属性5、使用requests发送get请求5.1  ...
    99+
    2024-04-02
  • Python requests模块怎么使用
    本文小编为大家详细介绍“Python requests模块怎么使用”,内容详细,步骤清晰,细节处理妥当,希望这篇“Python requests模块怎么使用”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习...
    99+
    2023-07-05
  • Python爬虫Requests库如何使用
    本篇内容主要讲解“Python爬虫Requests库如何使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Python爬虫Requests库如何使用”吧!1、安装 requests 库因为学习过...
    99+
    2023-07-06
  • python中怎么使用requests下载文件
    这篇文章主要介绍了python中怎么使用requests下载文件的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇python中怎么使用requests下载文件文章都会有所收获,下面我们一起来看看吧。使用reque...
    99+
    2023-06-29
  • python中requests模块怎么用
    这篇文章将为大家详细讲解有关python中requests模块怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。Requests模块是一个用于网络请求的模块,主要用来模拟浏览器发请求。其实类似的模块有很...
    99+
    2023-06-29
  • Python爬虫Requests库的使用详情
    目录一、Requests库的7个主要的方法二、Response对象的属性三、爬取网页通用代码四、Resquests库的常见异常五、Robots协议展示六、案例展示一、Requests...
    99+
    2024-04-02
  • Python中requests库的用法详解
    目录一、requests库安装请求响应二、发送get请求1、一个带参数的get请求:2、响应json3、添加头信息headers4、添加和获取cookie信息三、发送post请求1、...
    99+
    2024-04-02
  • Python之requests怎么安装使用
    1.准备工作首先呢,我们要确保我们已经之前安装requests库,如果没有安装,按照下面步骤按照库。pip 安装无论是 Windows、Linux 还是 Mac,都可以通过 pip 这个包管理工具来安装。在命令行下运行如下命令即可完成 re...
    99+
    2023-05-18
    Python Requests
  • Python中urllib库和requests库区别
    本篇内容主要讲解“Python中urllib库和requests库区别”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Python中urllib库和requests库区别”吧!一、前言在使用Pyt...
    99+
    2023-06-15
  • Python HTTP库 requests 的简单使用详情
    目录1、简单使用2、构建请求查询参数3、构建请求头Headers4、构建POST请求数据 4.1 表单数据4.2 json数据5、获取响应内容6、Cookies7、超时配置8、代理r...
    99+
    2024-04-02
  • python爬虫之requests库的使用详解
    目录python爬虫—requests库的用法基本的get请求带参数的GET请求:解析json使用代理获取cookie会话维持证书验证设置超时异常捕获异常处理 总结 python爬虫...
    99+
    2024-04-02
  • Python网络爬虫requests库如何使用
    这篇文章主要讲解了“Python网络爬虫requests库如何使用”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Python网络爬虫requests库如何使用”吧!1. 什么是网络爬虫简单来...
    99+
    2023-07-06
  • python中如何导入requests库
    python中导入requests库的方法:1、在win操作系统中找到python程序目录;2、打开idle工具;3、在idle中新建一个shell脚本;4、输入“import requests”指令导入requests库即可具体操作方法:...
    99+
    2024-04-02
  • python爬虫之requests库使用代理方式
    目录安装上requests库GET方法谷歌浏览器的开发者工具POST方法使用代理在看这篇文章之前,需要大家掌握的知识技能: python基础html基础http状态码 让我们看看这篇...
    99+
    2024-04-02
  • Python中requests库的基本概念与具体使用方法
    目录一、 基本概念1、 简介2、 获取3、 http 协议3.1 URL3.2 常用 http 请求方法二、 使用方法1、 基本语法2、 具体使用方法2.1 get2.2 post2...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作