No project description provided
Project description
zdppy_requests
基于requests二开的HTTP请求库,无任何第三方依赖,可独立使用,不受开源框架迭代的影响。
使用示例
安装
pip install zdppy_requests
获取网页源码
import zdppy_requests as zr
response = zr.get("https://www.baidu.com/")
print(response.status_code)
print(response.text)
创建Mapping
import zdppy_requests as zr
from zdppy_requests.auth import HTTPBasicAuth
url = "http://localhost:9200"
body = {
"mappings": {
"properties": {
"name": {
"type": "text"
},
"price": {
"type": "double"
},
"author": {
"type": "text"
},
"pub_date": {
"type": "date"
}
}
}
}
index = "books"
auth = HTTPBasicAuth('elastic','zhangdapeng520')
response = zr.put(f"{url}/{index}", json=body, auth=auth)
print(response.status_code)
print(response.text)
查询Mapping
import zdppy_requests as zr
from zdppy_requests.auth import HTTPBasicAuth
url = "http://localhost:9200"
index = "books/_mapping?pretty"
auth = HTTPBasicAuth('elastic','zhangdapeng520')
target = f"{url}/{index}"
response = zr.get(target, auth=auth)
print(response.status_code)
print(response.text)
删除Mapping
import zdppy_requests as zr
from zdppy_requests.auth import HTTPBasicAuth
url = "http://localhost:9200"
index = "books"
auth = HTTPBasicAuth('elastic','zhangdapeng520')
target = f"{url}/{index}"
response = zr.delete(target, auth=auth)
print(response.status_code)
print(response.text)
根据ID新增数据
import zdppy_requests as zr
from zdppy_requests.auth import HTTPBasicAuth
url = "http://localhost:9200"
index = "books/_doc"
did = "1"
auth = HTTPBasicAuth('elastic','zhangdapeng520')
target = f"{url}/{index}/{did}"
body = {
"name": "《JavaScript全栈开发实战》",
"author": "张大鹏",
"price": 123,
"pub_date": "2019-12-12"
}
response = zr.put(target, json=body, auth=auth)
print(response.status_code)
print(response.text)
根据ID查询图书
import zdppy_requests as zr
from zdppy_requests.auth import HTTPBasicAuth
url = "http://localhost:9200"
index = "books/_doc"
did = "1"
auth = HTTPBasicAuth('elastic','zhangdapeng520')
target = f"{url}/{index}/{did}"
response = zr.get(target, auth=auth)
print(response.status_code)
print(response.text)
根据ID删除图书
import zdppy_requests as zr
from zdppy_requests.auth import HTTPBasicAuth
url = "http://localhost:9200"
index = "books/_doc"
did = "1"
auth = HTTPBasicAuth('elastic','zhangdapeng520')
target = f"{url}/{index}/{did}"
response = zr.delete(target, auth=auth)
print(response.status_code)
print(response.text)
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
zdppy_requests-0.1.3.tar.gz
(387.9 kB
view hashes)
Built Distribution
zdppy_requests-0.1.3-py3-none-any.whl
(413.5 kB
view hashes)
Close
Hashes for zdppy_requests-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9fb9be97d379c6ca6f35c4a6a118326c418777f8d2a3c8b2f046218145c2731 |
|
MD5 | b1179b160bd25b6650359e7570e15847 |
|
BLAKE2b-256 | a62f7835586867d1286da95fc4c1371e244b4a4940ddc1de359ee1e8db15abcc |