感觉这样写起来贼方便,突然就明白了二次封装
的好处了
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)
https://github.com/0Chencc/SimpleRequestFramework