Encapsulates a framework for requests to request json corresponding package api, while saving the results locally
Project description
SimpleRequestsFramework
Description
This is a simple will be used to request requests wrapped up response package is json at the same time the content will be stored locally api package . Support for GET and POST requests , while supporting multiple proxy protocols , you can preset the Header and other related information .
Installation
pip install simple-requests-framework
Usage
from SimpleRequestFramework import SimpleRequestFramework
custom_headers = {
"User-Agent": "CustomUserAgent/1.0",
"Authorization": "Bearer YOUR_TOKEN"
}
# new a framework instance, and set the save directory, use proxy, proxy type, proxy address, and custom headers
framework = SimpleRequestFramework(
save_directory="output_files",
use_proxy=True,
proxy_type="http",
proxy_address="http://127.0.0.1:8080",
headers=custom_headers
)
# GET request example
get_url = "https://api.ip.sb/ip"
params = {
"param1": "value1",
"param2": "value2"
}
framework.fetch_and_save(get_url, "output_get.json", method="GET", params=params)
# POST request example
post_url = "https://httpbin.org/post"
data = {
"data1": "value1",
"data2": "value2"
}
framework.fetch_and_save(post_url, "output_post.json", method="POST", data=data)
Also supports configuration of framework instances as json files
create a json file named config.json
{
"save_directory": "output_files",
"use_proxy": true,
"proxy_type": "http",
"proxy_address": "http://127.0.0.1:8080",
"headers": {
"User-Agent": "CustomUserAgent/1.0",
"Authorization": "Bearer YOUR_TOKEN"
}
}
from SimpleRequestFramework import SimpleRequestFramework
framework = SimpleRequestFramework(config_json="config.json")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file simple-request-framework-0.0.2.tar.gz.
File metadata
- Download URL: simple-request-framework-0.0.2.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5aecc4ab6ea4e513ad8b54c3b242299e4bcc3a0a7d57b48612122fa6dcac45c
|
|
| MD5 |
2345705fef00b70ad216212ccdabdd6b
|
|
| BLAKE2b-256 |
ed433f7393cd4e99082035c27ceb6d6177b49894b14d6c16253e2f0de219f35f
|