CurlFetch2Py - это библиотека на Python, предназначенная для парсинга команд curl и fetch, преобразуя их в структурированные объекты Python
Project description
curl_fetch2py
CurlFetch2Py — это библиотека на Python, предназначенная для парсинга команд curl и fetch, преобразуя их в
структурированные объекты Python. Это особенно полезно для преобразования сложных HTTP-запросов в формат,
который можно легко использовать с библиотекой requests и прочими подобными библиотеками на Python (например httpx).
Установка
Установить библиотеку можно через pip
pip install --upgrade curl_fetch2py
Пример использования
import requests
from curl_fetch2py import CurlFetch2Py
# работа с CURL (bash/windows) строкой
curl_str = ('curl "https://www.python.org/" --compressed -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; '
'rv:128.0) Gecko/20100101 Firefox/128.0" -H "Accept: text/html,application/xhtml+xml,'
'application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8" -H "Accept-Language: '
'en-US,en;q=0.5" -H "Accept-Encoding: gzip, deflate, br, zstd" -H "Referer: https://www.google.com/" -H '
'"Connection: keep-alive" -H "Cookie: _ga_TF35YF9CVH=GS1.1.1722329638.1.0.1722329638.0.0.0; '
'_ga=GA1.1.1890680152.1722329639; __utma=32101439.1890680152.1722329639.1722329639.1722329639.1; '
'__utmb=32101439.1.10.1722329639; __utmc=32101439; __utmz=32101439.1722329639.1.1.utmcsr=google^|utmccn=('
'organic)^|utmcmd=organic^|utmctr=(not^%^20provided); __utmt=1" -H "Upgrade-Insecure-Requests: 1" -H '
'"Sec-Fetch-Dest: document" -H "Sec-Fetch-Mode: navigate" -H "Sec-Fetch-Site: cross-site" -H '
'"Sec-Fetch-User: ?1" -H "Priority: u=0, i" -H "TE: trailers"')
context_curl = CurlFetch2Py.parse_curl_context(curl_str)
request_curl = requests.get(url=context_curl.url, headers=context_curl.headers, cookies=context_curl.cookies)
with open('result_curl.html', 'w', encoding='utf-8') as result:
result.write(request_curl.text)
# работа с FETCH строкой
fetch_str = '''
await fetch("https://www.python.org/", {
"credentials": "include",
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Upgrade-Insecure-Requests": "1",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "cross-site",
"Sec-Fetch-User": "?1",
"Priority": "u=0, i"
},
"referrer": "https://www.google.com/",
"method": "GET",
"mode": "cors"
});
'''
request_fetch = requests.get(url=context_curl.url, headers=context_curl.headers, cookies=context_curl.cookies)
with open('result_fetch.html', 'w', encoding='utf-8') as result:
result.write(request_fetch.text)
License
Этот проект лицензируется по лицензии MIT.
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
curl_fetch2py-0.1.tar.gz
(4.7 kB
view details)
Built Distribution
File details
Details for the file curl_fetch2py-0.1.tar.gz
.
File metadata
- Download URL: curl_fetch2py-0.1.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02973e7d1e0e014eeccb536b36deb76fcfed5c6c1e0051f2a66e0f6f7315fcbe |
|
MD5 | b22acfc3838bddd46ab99cc14b55a9ac |
|
BLAKE2b-256 | 040af2b0dc82bc98696a70b589c2fe61b9a552e75d9a2acd48c179b696119ad6 |
File details
Details for the file curl_fetch2py-0.1-py3-none-any.whl
.
File metadata
- Download URL: curl_fetch2py-0.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c76ae58b59c254ef1b94ef01759ee2e0fa3d041eebded2c419302eebf9b2247 |
|
MD5 | 4486b77f463901dd0cff47f08c6e9dca |
|
BLAKE2b-256 | e16b56e6b96cb79b80014fe5812cb22346c3d0e3b501f34345f7e27ba894ccdb |