Python中requests库使用方法详解

2023-05-16

python中requests库使用方法详解

  • 前言:
    • 一、什么是Requests
    • 二、安装Requests库
    • 三、各种请求方式
      • 1. 基本的GET请求
      • 2. 带参数的GET请求
      • 3. 解析json
      • 4. 获取二进制数据
      • 5. 添加headers
      • 6. 基本POST请求
    • 三、响应
    • 四、高级操作
      • 1. 文件上传
      • 2. 获取cookie
      • 3. 会话维持、模拟登陆
      • 4. 代理设置
      • 5. 异常处理

前言:

开发环境:Windows10专业版
开发软件:Pycharm Community 2022.3

一、什么是Requests

Requests 是⽤Python语⾔编写,基于urllib,采⽤Apache2 Licensed开源协议的 HTTP 库。它⽐ urllib 更加⽅便,可以节约我们⼤量的⼯作,完全满⾜HTTP测试需求。

二、安装Requests库

在前面的Python基础中我们已经在电脑中配置好了Python环境

如果你还没有安装Python环境可以参考我的这篇文章Python基础——0.Python环境的安装___H2__的博客-CSDN博客

进入命令行win+R执行命令提示符

输入:pip install requests 即可开始安装requests库

项目导入requests:import requests

三、各种请求方式

各种请求方式的使用方法是:

import requests

requests.post('http://httpbin.org/post')
requests.put('http://httpbin.org/put')
requests.delete('http://httpbin.org/delete')
requests.head('http://httpbin.org/get')
requests.options('http://httpbin.org/get')

这五种请求的意义分别是:

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

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

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

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

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

**get 和 post比较常见 **

GET:请求将提交的数据放置在HTTP请求协议头中;

POST:提交的数据则放在实体数据中

1. 基本的GET请求

import requests
 
response = requests.get('http://httpbin.org/get')
print(response.text)

返回结果:

<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>ç™¾åº¦ä¸€ä¸‹ï¼Œä½ å°±çŸ¥é“</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>æ–°é—»</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>å
³äºŽç™¾åº¦</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前å¿
读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a>&nbsp;京ICP证030173号&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

2. 带参数的GET请求

将name和age传进去

import requests
response = requests.get("http://httpbin.org/get?name=germey&age=22")
print(response.text)
{
  "args": {
    "age": "22", 
    "name": "germey"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Connection": "close", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.18.4"
  }, 
  "origin": "183.64.61.29", 
  "url": "http://httpbin.org/get?name=germey&age=22"
}

或者使用params的方法:

import requests
 
data = {
 'name': 'germey',
 'age': 22
}
response = requests.get("http://httpbin.org/get", params=data)
print(response.text)

输出结果:

{
  "args": {
    "age": "22", 
    "name": "germey"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.28.2", 
    "X-Amzn-Trace-Id": "Root=1-63dbab1e-10a0b6a747231aa8069318fb"
  }, 
  "origin": "117.44.70.180", 
  "url": "http://httpbin.org/get?name=germey&age=22"
}

3. 解析json

将返回值以json的形式展示:

import requests
import json
 
response = requests.get("http://httpbin.org/get")

print(type(response.text))
print(response.json())
print(json.loads(response.text))
print(type(response.json()))

运行结果:

<class 'str'>

{'args': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}, 'origin': '183.64.61.29', 'url': 'http://httpbin.org/get'}

{'args': {}, 'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Connection': 'close', 'Host': 'httpbin.org', 'User-Agent': 'python-requests/2.18.4'}, 'origin': '183.64.61.29', 'url': 'http://httpbin.org/get'}

<class 'dict'>

4. 获取二进制数据

记住返回值.content就ok了

import requests
 
response = requests.get("https://github.com/favicon.ico")
print(type(response.text), type(response.content))
print(response.text)
print(response.content)

返回值是非常长的01二进制字符串所以在此不做演示。

5. 添加headers

在访问次数过多被服务器认定为爬虫攻击时,短时间内可能会将你的IP封禁,这代表你两个小时内将无法使用继续你的爬虫代码调试

,所以我们一般会添加hearder参数。

当传入headers时:

import requests
 
headers = {
 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36'
}
response = requests.get("https://www.csdn.net/", headers=headers)
print(response.text)

输出结果是csdn首页的html页面源代码

6. 基本POST请求

import requests
 
data = {'name': 'germey', 'age': '22'}
response = requests.post("http://httpbin.org/post", data=data)
print(response.text)

运行结果:

{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "age": "22", 
    "name": "germey"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Content-Length": "18", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.28.2", 
    "X-Amzn-Trace-Id": "Root=1-63dbac35-180f5a89233e7d6b4fe75688"
  }, 
  "json": null, 
  "origin": "117.44.70.180", 
  "url": "http://httpbin.org/post"
}

三、响应

import requests

response = requests.get('https://www.jianshu.com/')
print(type(response.status_code), response.status_code)
print(type(response.headers), response.headers)
print(type(response.cookies), response.cookies)
print(type(response.url), response.url)
print(type(response.history), response.history)

运行结果:

<class 'int'> 403
<class 'requests.structures.CaseInsensitiveDict'> {'Server': 'Tengine', 'Date': 'Thu, 02 Feb 2023 12:28:21 GMT', 'Content-Type': 'text/html', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Vary': 'Accept-Encoding', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Content-Encoding': 'gzip'}
<class 'requests.cookies.RequestsCookieJar'> <RequestsCookieJar[]>
<class 'str'> https://www.jianshu.com/
<class 'list'> []

状态码判断:常见的网页状态码:

100: ('continue',),
101: ('switching_protocols',),
102: ('processing',),
103: ('checkpoint',),
122: ('uri_too_long', 'request_uri_too_long'),
200: ('ok', 'okay', 'all_ok', 'all_okay', 'all_good', '\\o/', '✓'),
201: ('created',),
202: ('accepted',),
203: ('non_authoritative_info', 'non_authoritative_information'),
204: ('no_content',),
205: ('reset_content', 'reset'),
206: ('partial_content', 'partial'),
207: ('multi_status', 'multiple_status', 'multi_stati', 'multiple_stati'),
208: ('already_reported',),
226: ('im_used',),
 
# Redirection.
300: ('multiple_choices',),
301: ('moved_permanently', 'moved', '\\o-'),
302: ('found',),
303: ('see_other', 'other'),
304: ('not_modified',),
305: ('use_proxy',),
306: ('switch_proxy',),
307: ('temporary_redirect', 'temporary_moved', 'temporary'),
308: ('permanent_redirect',
 'resume_incomplete', 'resume',), # These 2 to be removed in 3.0
 
# Client Error.
400: ('bad_request', 'bad'),
401: ('unauthorized',),
402: ('payment_required', 'payment'),
403: ('forbidden',),
404: ('not_found', '-o-'),
405: ('method_not_allowed', 'not_allowed'),
406: ('not_acceptable',),
407: ('proxy_authentication_required', 'proxy_auth', 'proxy_authentication'),
408: ('request_timeout', 'timeout'),
409: ('conflict',),
410: ('gone',),
411: ('length_required',),
412: ('precondition_failed', 'precondition'),
413: ('request_entity_too_large',),
414: ('request_uri_too_large',),
415: ('unsupported_media_type', 'unsupported_media', 'media_type'),
416: ('requested_range_not_satisfiable', 'requested_range', 'range_not_satisfiable'),
417: ('expectation_failed',),
418: ('im_a_teapot', 'teapot', 'i_am_a_teapot'),
421: ('misdirected_request',),
422: ('unprocessable_entity', 'unprocessable'),
423: ('locked',),
424: ('failed_dependency', 'dependency'),
425: ('unordered_collection', 'unordered'),
426: ('upgrade_required', 'upgrade'),
428: ('precondition_required', 'precondition'),
429: ('too_many_requests', 'too_many'),
431: ('header_fields_too_large', 'fields_too_large'),
444: ('no_response', 'none'),
449: ('retry_with', 'retry'),
450: ('blocked_by_windows_parental_controls', 'parental_controls'),
451: ('unavailable_for_legal_reasons', 'legal_reasons'),
499: ('client_closed_request',),
 
# Server Error.
500: ('internal_server_error', 'server_error', '/o\\', '✗'),
501: ('not_implemented',),
502: ('bad_gateway',),
503: ('service_unavailable', 'unavailable'),
504: ('gateway_timeout',),
505: ('http_version_not_supported', 'http_version'),
506: ('variant_also_negotiates',),
507: ('insufficient_storage',),
509: ('bandwidth_limit_exceeded', 'bandwidth'),
510: ('not_extended',),
511: ('network_authentication_required', 'network_auth', 'network_authentication'),

四、高级操作

1. 文件上传

使用 Requests 模块,上传文件也是如此简单的,文件的类型会自动进行处理:

import requests
 
files = {'file': open('cookie.txt', 'rb')}
response = requests.post("http://httpbin.org/post", files=files)
print(response.text)

通过测试网站做的一个测试

我们先在当前Python文件的目录下建一个名为hello.txt的文本文档,在里面输入helloworld!

保存此文件后运行以上代码,输出结果如下:

{
  "args": {}, 
  "data": "", 
  "files": {
    "file": "helloworld!"
  }, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Content-Length": "156", 
    "Content-Type": "multipart/form-data; boundary=2954083cd56e685e1b45f9840426b548", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.28.2", 
    "X-Amzn-Trace-Id": "Root=1-63dbad05-039a79aa0adbc2733eab773b"
  }, 
  "json": null, 
  "origin": "117.44.70.180", 
  "url": "http://httpbin.org/post"
}

2. 获取cookie

当需要cookie时,直接调用response.cookie:(response为请求后的返回值)

import requests

response = requests.get("https://www.baidu.com/")
print(response.cookies)

for key, value in response.cookies.items():
    print(key + '=' + value)

输出结果:

<RequestsCookieJar[<Cookie BDORZ=27315 for .baidu.com/>]>
BDORZ=27315

3. 会话维持、模拟登陆

如果某个响应中包含一些Cookie,你可以快速访问它们:

import requests
 
r = requests.get('http://www.google.com.hk/')
print(r.cookies['NID'])
print(tuple(r.cookies))

要想发送你的cookies到服务器,可以使用 cookies 参数:

import requests

headers = {
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/"
                  "537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
}

# 在Cookie Version 0中规定空格、方括号、圆括号、等于号、逗号、双引号、斜杠、问号、@,冒号,分号等特殊符号都不能作为Cookie的内容。

cookies = {"cookie_name": "cookie_value", }
response = requests.get("https://www.baidu.com", headers=headers, cookies=cookies)
print(response.text)

输出结果是网页的html代码

4. 代理设置

在进行爬虫爬取时,有时候爬虫会被服务器给屏蔽掉,这时采用的方法主要有降低访问时间,通过代理ip访问,如下:

import requests
 
proxies = {
 "http": "http://127.0.0.1:9743",
 "https": "https://127.0.0.1:9743",
}
 
response = requests.get("https://www.taobao.com", proxies=proxies)
print(response.status_code)

ip可以从网上抓取,或者某宝购买

超时设置

访问有些网站时可能会超时,这时设置好timeout就可以解决这个问题

import requests
from requests.exceptions import ReadTimeout

try:
     response = requests.get("http://httpbin.org/get", timeout = 0.5)
     print(response.status_code)
except ReadTimeout:
     print('Timeout')

正常访问,状态码将返回200,超时则会输出Timeout

5. 异常处理

遇到网络问题(如:DNS查询失败、拒绝连接等)时,Requests会抛出一个ConnectionError 异常。

遇到罕见的无效HTTP响应时,Requests则会抛出一个 HTTPError 异常。

若请求超时,则抛出一个 Timeout 异常。

若请求超过了设定的最大重定向次数,则会抛出一个 TooManyRedirects 异常。

所有Requests显式抛出的异常都继承自 requests.exceptions.RequestException 。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python中requests库使用方法详解 的相关文章

  • QT/C++——网络编程

    目录 一 基础知识复习 二 UDP 客户端 xff1a 服务器 xff1a 三 TCP 服务器 xff1a 客户端 xff1a 四 小项目 客户端 xff1a 服务器 xff1a 一 基础知识复习 这部分内容前面讲的比较详细 xff0c 现
  • Linux驱动开发——高级I/O操作(一)

    一个设备除了能通过读写操作来收发数据或返回 保存数据 xff0c 还应该有很多其他的操作 比如一个串口设备还应该具备波特率获取和设置 帧格式获取和设置的操作 一个LED设备甚至不应该有读写操作 xff0c 而应该具备点灯和灭灯的操作 硬件设
  • ubuntu22.04安装与配置

    目录 一 环境及下载 iso下载 VM配置 二 虚拟机与环境配置 虚拟机开始后的配置 一些工具配置 参考 xff1a VMware Workstation Pro 文档 一 环境及下载 iso下载 Download Ubuntu Deskt
  • Linux——互斥与同步

    目录 一种典型的竞态 内核中的并发 中断屏蔽 原子变量 自旋锁 读写锁 顺序锁 一种典型的竞态 假设整型变量i是驱动代码中的一个个全局变量 xff0c 在驱动的某个例程中执行了i 43 43 操作 xff0c 而在中断服务程序中也执行了i
  • 基于max30102的物联网病房监测系统(传感驱动和数据处理)

    目录 一 实物展示 二 主体介绍 三 MAX30102的驱动 四 MAX30102的数据处理 奋斗一个星期 xff0c 每个引脚都是扒皮焊接然后再把皮包回去的 这几天吸的垃圾气体感觉要少活两年 一 实物展示 这次吸取上次教训 xff0c 把
  • 基于max30102的物联网病房监测系统(中断处理和主题逻辑)

    目录 五 中断处理 六 主体框架 对采集数据的初始化 核心功能的实现 烟雾 通信帧格式 wifi接收数据的处理 OLED显示 五 中断处理 void SysTick Handler void TimingDelay Decrement vo
  • 无人机4G数传方案(合宙cat1模块)

    一 合宙Cat1简介 YED C724 核心板是由银尔达 xff08 yinerda xff09 基于合宙 Air724 模组推出的低功耗 xff0c 超小体积 xff0c 高性能嵌入式 4G Cat1 核心版 xff0c 标准的 2 54
  • C++学习ros2话题机制(发布与订阅)

    C 43 43 学习ros2 一 创建文件和文件夹1 结构2 创建工作空间和工作包3 直接创建node cpp文件 二 编写节点文件 xff08 发布订阅 xff09 1 node1 cpp xff08 发布 xff09 2 CMakeLi
  • AttributeError: module ‘keras.backend’ has no attribute ‘set_image_dim_ordering’

    问题 原始代码如下 xff1a keras span class token punctuation span backend span class token punctuation span set image dim ordering
  • openmv识别红色物体并返回坐标给stm32单片机,通过pid控制舵机云台

    本人搜索了有关于舵机云台pid控制的代码 xff0c 但是都没有搜到想要的结果 xff0c 现在自己写出来了代码 xff0c 所以就将自己写的代码分享出来 xff0c 和大家一起学习进步 1 openmv识别红色物体 43 返回中心坐标的的
  • vs解决报错:C++ qualified name is not allowed(E0283)

    我们看 把在GCC下编译过关的c 43 43 程序放在vs下却不能过 仅给出部分代码 其他以此类推 先不要慌着改 看下详细信息 看上去都是语法错误 但这真的没任何语法错误啊 百度上查找下 报错信息都不一样 别人是类里面多加限定符 我这是正常
  • Linux下的man命令

    目录 一 man是什么 xff1f 二 man命令的使用1 通过man man查看man手册2 通过man来进行查询 四 总结 一 man是什么 xff1f man所代表的的是英文单词manual xff0c 也就是帮助手册的意思 xff0
  • IO多路复用之select

    目录 一 IO多路复用二 select函数三 select实现socket服务器 xff08 1 xff09 流程图 xff1a xff08 2 xff09 代码讲解 xff1a 四 总结代码示例 xff1a 一 IO多路复用 IO多路复用
  • curl 和 wget 命令下载

    curl 和 wget 命令下载 一 wget下载1 wget介绍2 wget下载方法 二 curl下载1 curl介绍2 curl下载方法 三 wget下载sqlite实例总结 一 wget下载 1 wget介绍 wget 是一个从网络上
  • Linux下载安装和使用SQLite

    Linux安装SQLite 一 SQLite下载二 SQLite安装三 SQLite的使用1 解决无法直接用sqlit3命令2 解决无法编译的问题 总结 一 SQLite下载 首先 xff0c 前往SQLite官网下载页面找到包含confi
  • 解决:‘config.status: error: Something went wrong bootstrapping makefile fragments......’问题

    解决 xff1a config status error Something went wrong bootstrapping makefile fragments 问题 一 问题二 解决方法 一 问题 首先我们来看安装sqlite时报的这
  • TFTP服务器搭建与使用

    文章目录 一 TFTP协议二 TFTP服务器搭建1 安装TFTP服务器2 创建TFTP服务文件夹3 配置tftp文件4 配置tftpd hpa文件 三 TFTP服务器使用 一 TFTP协议 TFTP xff08 Trivial File T
  • 深入探讨Linux驱动开发:Linux设备树

    文章目录 一 设备树介绍二 设备树框架1 设备树框架2 节点基本格式3 节点部分属性简介 总结 一 设备树介绍 设备树 xff08 Device Tree xff0c 简称 DT xff09 是一种在嵌入式系统中描述硬件设备的一种数据结构和
  • 深入探讨Linux驱动开发:驱动介绍与hello驱动实例

    文章目录 前言一 Linux驱动介绍1 用户态和内核态2 内核功能介绍3 驱动程序介绍 二 驱动程序分类与注意事项1 驱动程序分类2 内核驱动开发注意事项 三 hello驱动开发1 驱动模块2 模块加载和卸载函数3 编写hello模块4 M
  • ROS中使用乐视 奥比中光(Astra Pro)深度相机显示彩色和深度图像

    环境 UbuntuROS Kinect or Melodic 奥比中光ROS驱动包安装地址 xff1a https github com orbbec ros astra camera 1 安装ROS 2 安装依赖 span class t

随机推荐

  • 深入探讨Linux驱动开发:字符设备驱动开发与测试

    文章目录 一 字符设备驱动介绍1 设备驱动介绍 二 设备号1 设备号介绍2 分配与释放设备编号 dev t类型 静态分配设备号 动态分配设备号 释放主次设备号 手动创建设备节点 自动创建设备节点 删除设备节点 三 字符设备注册1 cdev结
  • ZED-深度感知使用

    文章目录 1 深度感知配置2 得到深度数据2 1 得到深度值 3 展示深度图4 获取点云数据4 1 从点云数据中计算距离 5 得到法线图像6 调整深度分辨率 1 深度感知配置 可以在初始化时使用InitParameters xff0c 在运
  • Linux系统之 开机自启动程序脚本 编写

    Linux系统启动加载程序 最近完成了项目 xff0c 来个开机自启运行 找到已编译好的程序 xff08 以下是我编译的house xff09 span class token function ls span l span class t
  • 算法时间复杂度、空间复杂度分析

    算法时间复杂度 在计算机程序编写前 xff0c 依据统计方法对算法进行估算 xff0c 经过总结 xff0c 我们发现一个高级语言编写的程序程序在计算机上运行所消耗的时间取决于下列因素 1 算法采用的策略和方案 编译产生的代码质量 3 问题
  • Linux 选择题一百道

    cron 后台常驻程序 daemon 用于 xff1a A 负责文件在网络中的共享 B 管理打印子系统 C 跟踪管理系统信息和错误 D 管理系统日常任务的调度 在大多数Linux发行版本中 xff0c 以下哪个属于块设备 block dev
  • 程序返回return与系统退出exit

    程序返回return与系统退出exit return是语言级别的 xff0c 它表示了调用堆栈的返回 xff1b exit则是系统调用级别的 xff0c 它表示了一个进程的结束 return是返回函数调用 xff0c 如果返回的是main函
  • 结构体、结构体变量、结构体指针、字符串

    结构体 数组是用于保存一组相同类型数据的 而结构体是用于保存一组不同类型数组的 在使用结构体之前必须先定义结构体类型 因为C语言不知道你的结构体中需要存储哪些类型数据 我们必须通过定义结构体类型来告诉C语言 我们的结构体中需要存储哪些类型的
  • linux下脚本实现 切换root用户并执行

    借助一个工具 expect sudo apt span class token operator span get install expect 编写脚本 xff1a vim root sh span class token operato
  • csdn极客江南

    零基础学会 C 语言课程学习突破 1500 人 xff1a 学习地址 xff1a https edu csdn net course detail 31452 spm 61 1001 2014 3001 5507TS TS 专栏文章更新至第
  • 音视频编码格式认知

    编码格式对应的就是音频编码和视频编码 xff0c 音频编码标准和视频编码标准 xff0c 每种编码标准都对应的编码算法 xff0c 其目的是通过一定编码算法实现数据的压缩 减少数据的冗余 视频编码指的是通过特定的压缩技术 xff0c 将某个
  • TensorFlow、PyTorch各版本对应的CUDA、cuDNN关系

    TensorFlow PyTorch各版本对应的CUDA cuDNN关系 xff08 截止2021年4月7日 xff09 TensorFowLinuxCPUGPU macOSCPUGPU WindowsCPUGPU PyTorchCPUGP
  • Android源码新大陆

    vold amp av http aospxref com android 13 0 0 r3 xref system vold model http aospxref com android 13 0 0 r3 xref framewor
  • QT读取GPS模块时,显示不完全,一条指令只能ReadAll32个字节,数据被分开

    在用QT读取GPS模块的时候 xff0c 发现读取到的数据总是显示不出来经度 xff0c 用debug调试 xff0c 发现数据被分开 xff0c 一条指令只能读到N那里 xff0c GNRMC 064401 65 A 3110 47069
  • STM32CubeMX配置串口DMA传输实现不定长数据收发

    串口简介 串口是全双工的串行通信协议 串口通信指串口按位 xff08 bit xff09 发送和接收字节 xff08 一个字节有8位 xff09 尽管比特字节 xff08 byte xff09 的串行通信慢 xff0c 但是串口可以在使用一
  • 单片机串口不够用怎么办?

    扩展串口 一 为什么要扩展串口 xff1f 一块单片机的串口是有限的 xff0c 一般2 4个 当我们做一个项目时需要连接多个外设时跟单片机通讯时 xff0c 且通讯都是以串口形式 那么我们只能去扩展串口来满足我们的应用需求 二 解决方法
  • C语言:自定义实现strcat函数

    include lt stdio h gt include lt assert h gt char My Strcat char str1 const char str2 assert str1 amp amp str2 指针不为空 cha
  • 了解串口协议,及完成STM32的USART串口通讯程序,并用keil观察波形

    文章目录 前言一 串口协议1 RS 2322 485标准 二 RS 232 485和TTL电平1 RS 232电平2 4853 TTL电平4 区别 三 USB TTL转2321 CH3402 发送接收3 USB转RS 232 四 完成一个S
  • UART RS232 RS485协议原理及应用

    一 URAT UART Universal Asynchronous Receiver Transmitter 通用异步收发传输器 xff0c 简称串口 xff0c 是设备间进行异步通信的模块 UART负责处理数据总线和串行口之间的串 并
  • 2022年电赛E题声源定位跟踪系统

    我们组本来是奔着视觉题去的 xff0c 可是到比赛的时候突然发现好像就无人机比较合适 xff0c 但是我们都没玩过无人机 xff0c 本想转战小车 xff0c 可是材料突然发现要两辆小车 xff0c 材料也不够来不及买 xff0c 于是我们
  • Python中requests库使用方法详解

    python中requests库使用方法详解 前言 xff1a 一 什么是Requests二 安装Requests库三 各种请求方式1 基本的GET请求2 带参数的GET请求3 解析json4 获取二进制数据5 添加headers6 基本P