iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python中requests库的用法详解
  • 493
分享到

Python中requests库的用法详解

2024-04-02 19:04:59 493人浏览 安东尼

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

摘要

目录一、requests库安装请求响应二、发送get请求1、一个带参数的get请求:2、响应JSON3、添加头信息headers4、添加和获取cookie信息三、发送post请求1、

一、requests库

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

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

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

安装

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

官方中文教程地址:http://docs.python-requests.org/zh_CN/latest/user/quickstart.html

学习之前推荐一个非常好的http测试网站:http://httpbin.org,提供非常非常完善的接口调试、测试功能~

请求

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

  • GET: 请求指定的页面信息,并返回实体主体。
  • HEAD: 只请求页面的首部。
  • POST: 请求服务器接受所指定的文档作为对所标识的URI的新的从属实体。
  • PUT: 从客户端向服务器传送的数据取代指定的文档的内容。
  • DELETE: 请求服务器删除指定的页面。
  • OPTIONS: 允许客户端查看服务器的性能。

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

import requests

response = requests.get("https://www.baidu.com")# 打开网页获取响应
print('response:', type(response))# 打印响应类型,response: 
print('status_code:', response.status_code)# 打印状态码 ,status_code: 200
print('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-8
response.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; ubuntu; linux 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 requests
from 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 requests
response = 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_code
200
>>> r.history
[]

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

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

r = requests.get('http://github.com', allow_redirects=False)
>>> r.status_code
301
>>> 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.parse
import urllib.request
url = "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 requests
url = "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、首先登陆任何页面,获取cookie
i1 = 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 requests

session = 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 requests
from 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 time

import requests
from bs4 import BeautifulSoup

session = 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='/file/imgs/upload/202211/11/r4swcy0qfpl.jpg',
    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').string
print(nick_name)

4、 博客园

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re
import json
import base64

import rsa
import requests


def 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 value


session = 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-agent
r1 = 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库的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持编程网。

--结束END--

本文标题: Python中requests库的用法详解

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

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

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

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

下载Word文档
猜你喜欢
  • Python中requests库的用法详解
    目录一、requests库安装请求响应二、发送get请求1、一个带参数的get请求:2、响应json3、添加头信息headers4、添加和获取cookie信息三、发送post请求1、...
    99+
    2024-04-02
  • Python中requests库的学习方法详解
    目录前言一 URL,URI和URN1. URL,URI和URN2. URL的组成二 请求组成1. 请求方法2. 请求网址3. 请求头4. 请求体三 请求1. get请求2. get带...
    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库的用法基本的get请求带参数的GET请求:解析json使用代理获取cookie会话维持证书验证设置超时异常捕获异常处理 总结 python爬虫...
    99+
    2024-04-02
  • Python中requests库
    文章目录 requests库一、 基本概念1、 简介2、 获取3、 http 协议3.1 URL3.2 常用 http 请求方法 二、 使用方法1、 基本语法requests 库...
    99+
    2023-09-07
    python http 开发语言
  • Python 网页请求之requests库的使用详解
    目录1.requests库简介2.requests库方法介绍3.代码实例1.requests库简介 requests 是 Python 中比较常用的网页请求库,主要用来发送 HTTP...
    99+
    2024-04-02
  • Python爬虫Requests库的使用详情
    目录一、Requests库的7个主要的方法二、Response对象的属性三、爬取网页通用代码四、Resquests库的常见异常五、Robots协议展示六、案例展示一、Requests...
    99+
    2024-04-02
  • python使用requests库提交multipart/form-data请求的方法详解
    目录前言multipart/form-dataPython 发送 multipart/form-data补充知识:multipart/form-data 参数转码总结前言 今天渗透测...
    99+
    2023-01-17
    python multipart/form-data python formdata请求 python multipart/form-data请求
  • Python HTTP库 requests 的简单使用详情
    目录1、简单使用2、构建请求查询参数3、构建请求头Headers4、构建POST请求数据 4.1 表单数据4.2 json数据5、获取响应内容6、Cookies7、超时配置8、代理r...
    99+
    2024-04-02
  • Python爬取求职网requests库和BeautifulSoup库使用详解
    目录一、requests库1、requests简介2、安装requests库3、使用requests获取网页数据 我们先导入模块4、总结requests的一些方法二、Beautifu...
    99+
    2024-04-02
  • Python中requests库怎么使用
    这篇文章主要介绍了Python中requests库怎么使用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Python中requests库怎么使用文章都会有所收获,下面我们一起来看看吧。一、requests库re...
    99+
    2023-06-30
  • 详解python中flask_caching库的用法
    目录安装flask_caching库:缓存类型配置参数初始化使用缓存为了尽量减少缓存穿透,并同时减少web的响应时间,可以针对那些需要一定时间才能获取结果的函数和那些不需要频繁更新的...
    99+
    2023-05-19
    python flask flask_caching库
  • Python requests用法和django后台处理详解
    目录1、requests 的常见用法1.1、提交查询1.2、提交表格1.3、在提交时附加文件:1.4、保持状态1.5、查看结果2、django 的处理2.1、params 传入的参数...
    99+
    2024-04-02
  • python requests模块详解
    requests是python的一个HTTP客户端库,跟urllib,urllib2类似,那为什么要用requests而不用urllib2呢?官方文档中是这样说明的: python的标准库urllib2提供了大部分需要的HTTP功能,但是A...
    99+
    2023-01-31
    详解 模块 python
  • python—requests模块详解
    一、前言 1、requests简介 requests是一个很实用的Python HTTP客户端库,爬虫和测试服务器响应数据时经常会用到,它是python语言的第三方的库,专门用于发送HTTP请求,使用...
    99+
    2023-09-04
    python 开发语言 requests 网络爬虫
  • python中openpyxl库用法详解
    目录一、读取数据1.1 从工作簿中取得工作表1.2 从表中取得单元格1.3 从表中取得行和列二、写入数据2.1 创建Workbook对象来创建Excel文件并保存2.2 案例分析一 ...
    99+
    2024-04-02
  • 详解python中mongoengine库用法
    目录一、MongoDB的安装与连接二、MongoEngine模型介绍2.1、ODM模型介绍2.2、常见数据类型 2.3、数据类型通用参数2.4、类属性meta常见配置项2....
    99+
    2024-04-02
  • 详解基于pycharm的requests库使用教程
    目录requests库安装和导入requests库的get请求requests库的post请求requests库的代理requests库的cookie自动识别验证码requests库...
    99+
    2024-04-02
  • python的requests库和url
    python中有多种库可以用来处理http请求,比如python的原生库:urllib包、requests类库。urllib和urllib2是相互独立的模块,python3.0以上把urllib和urllib2合并成一个库了,request...
    99+
    2023-01-31
    python requests url
  • 离线安装python的requests库方法
    目录前言1、下载安装包1.1 检查requests模块所需依赖包1.2 下载requests所需依赖包1.3 下载requests包2、安装2.1 安装requests所需依赖包2....
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作