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.
Release files for curl-fetch2py 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| curl_fetch2py-0.1.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| curl_fetch2py-0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.7 kB
Release files / curl_fetch2py-0.1.tar.gz
| Download URL | curl_fetch2py-0.1.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
02973e7d1e0e014eeccb536b36deb76fcfed5c6c1e0051f2a66e0f6f7315fcbe
|
|
BLAKE2b-256 checksum How to use checksums |
040af2b0dc82bc98696a70b589c2fe61b9a552e75d9a2acd48c179b696119ad6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.1
|
Release files / curl_fetch2py-0.1-py3-none-any.whl
| Download URL | curl_fetch2py-0.1-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3c76ae58b59c254ef1b94ef01759ee2e0fa3d041eebded2c419302eebf9b2247
|
|
BLAKE2b-256 checksum How to use checksums |
e16b56e6b96cb79b80014fe5812cb22346c3d0e3b501f34345f7e27ba894ccdb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.1
|