中文的python网络请求库!
Project description
re_it 中文的python网络请求库!
如果程序错了,请报告给534047068@qq.com。
你可以按照以下步骤使用这个包,并在代码中添加注释以更好地理解其功能和用法:
导入 re_it 模块:from re_it import 请求
创建一个请求对象实例:
我的请求实例 = 请求.我的请求()
使用 添加头部()
方法为请求添加头部信息:
我的请求实例.添加头部('User-Agent', 'Mozilla/5.0') # 添加User-Agent头部信息
我的请求实例.添加头部('Content-Type', 'application/json') # 添加Authorization头部信息
发送 GET 请求并获取响应内容:
网址 = "www.example.com" # 设置目标网址
响应内容 = 我的请求实例.获取(网址) # 发送GET请求并获取响应内容
print(响应内容) # 打印响应内容
发送 POST 请求并获取响应内容:
网址 = "www.example.com" # 设置目标网址
数据 = "key1=value1&key2=value2" # 设置POST请求的数据,可选参数
响应内容 = 我的请求实例.提交(网址, 数据) # 发送POST请求并获取响应内容
print(响应内容) # 打印响应内容
输出:
<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
这个网络请求包中的函数有一些可选参数和必选参数。下面是每个函数的参数说明:
添加头部(self, 键, 值)
函数:
必选参数:
键
:要添加到请求头部的键。
值
:要添加到请求头部的值。
获取(self, 网址)
函数:
必选参数:
网址
:目标网址,用于建立连接并发送 GET 请求。
提交(self, 网址, 数据=None)
函数:
必选参数:
网址
:目标网址,用于建立连接并发送 POST 请求。
可选参数:
数据
:POST 请求的数据,使用 URL 编码格式(例如,"key1=value1&key2=value2")。默认值为 None,即没有请求数据。
所有的函数都是在一个名为 "我的请求" 的类中定义的,并且都需要通过类的实例进行调用(如 请求.函数名())。
需要注意的是,根据具体的使用情况,你可能需要根据需要自定义请求头部信息和请求数据,并根据目标网址发送相应的请求。
version : 1.0.0.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
re_it-1.0.0.1.tar.gz
(3.2 kB
view hashes)