# curl_fetch2py
```markdown
CurlFetch2Py — это библиотека на Python, предназначенная для парсинга команд curl и fetch, преобразуя их в
структурированные объекты Python. Это особенно полезно для преобразования сложных HTTP-запросов в формат,
который можно легко использовать с библиотекой requests и прочими подобными библиотеками на Python (например httpx).
```
## Установка
Установить библиотеку можно через pip
```bash
pip install --upgrade curl_fetch2py
```
## Пример использования
```python
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](https://choosealicense.com/licenses/mit/).
Raw data
{
"_id": null,
"home_page": "https://github.com/Yakvenalex/curl_fetch2py",
"name": "curl-fetch2py",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "Alexey Yakovenko",
"author_email": "mr.mnogo@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/04/0a/f2b0dc82bc98696a70b589c2fe61b9a552e75d9a2acd48c179b696119ad6/curl_fetch2py-0.1.tar.gz",
"platform": null,
"description": "# curl_fetch2py\r\n\r\n```markdown\r\nCurlFetch2Py \u2014 \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0430 Python, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u043a\u043e\u043c\u0430\u043d\u0434 curl \u0438 fetch, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044f \u0438\u0445 \u0432\r\n\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Python. \u042d\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u044b\u0445 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442,\r\n\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 requests \u0438 \u043f\u0440\u043e\u0447\u0438\u043c\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u043d\u0430 Python (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 httpx).\r\n```\r\n\r\n## \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430\r\n\r\n\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437 pip\r\n\r\n```bash\r\npip install --upgrade curl_fetch2py\r\n```\r\n\r\n## \u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f\r\n\r\n```python\r\nimport requests\r\nfrom curl_fetch2py import CurlFetch2Py\r\n\r\n\r\n# \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 CURL (bash/windows) \u0441\u0442\u0440\u043e\u043a\u043e\u0439\r\ncurl_str = ('curl \"https://www.python.org/\" --compressed -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; '\r\n 'rv:128.0) Gecko/20100101 Firefox/128.0\" -H \"Accept: text/html,application/xhtml+xml,'\r\n 'application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8\" -H \"Accept-Language: '\r\n 'en-US,en;q=0.5\" -H \"Accept-Encoding: gzip, deflate, br, zstd\" -H \"Referer: https://www.google.com/\" -H '\r\n '\"Connection: keep-alive\" -H \"Cookie: _ga_TF35YF9CVH=GS1.1.1722329638.1.0.1722329638.0.0.0; '\r\n '_ga=GA1.1.1890680152.1722329639; __utma=32101439.1890680152.1722329639.1722329639.1722329639.1; '\r\n '__utmb=32101439.1.10.1722329639; __utmc=32101439; __utmz=32101439.1722329639.1.1.utmcsr=google^|utmccn=('\r\n 'organic)^|utmcmd=organic^|utmctr=(not^%^20provided); __utmt=1\" -H \"Upgrade-Insecure-Requests: 1\" -H '\r\n '\"Sec-Fetch-Dest: document\" -H \"Sec-Fetch-Mode: navigate\" -H \"Sec-Fetch-Site: cross-site\" -H '\r\n '\"Sec-Fetch-User: ?1\" -H \"Priority: u=0, i\" -H \"TE: trailers\"')\r\n\r\ncontext_curl = CurlFetch2Py.parse_curl_context(curl_str)\r\nrequest_curl = requests.get(url=context_curl.url, headers=context_curl.headers, cookies=context_curl.cookies)\r\n\r\nwith open('result_curl.html', 'w', encoding='utf-8') as result:\r\n result.write(request_curl.text)\r\n\r\n# \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 FETCH \u0441\u0442\u0440\u043e\u043a\u043e\u0439\r\nfetch_str = '''\r\nawait fetch(\"https://www.python.org/\", {\r\n \"credentials\": \"include\",\r\n \"headers\": {\r\n \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0\",\r\n \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,*/*;q=0.8\",\r\n \"Accept-Language\": \"en-US,en;q=0.5\",\r\n \"Upgrade-Insecure-Requests\": \"1\",\r\n \"Sec-Fetch-Dest\": \"document\",\r\n \"Sec-Fetch-Mode\": \"navigate\",\r\n \"Sec-Fetch-Site\": \"cross-site\",\r\n \"Sec-Fetch-User\": \"?1\",\r\n \"Priority\": \"u=0, i\"\r\n },\r\n \"referrer\": \"https://www.google.com/\",\r\n \"method\": \"GET\",\r\n \"mode\": \"cors\"\r\n});\r\n'''\r\nrequest_fetch = requests.get(url=context_curl.url, headers=context_curl.headers, cookies=context_curl.cookies)\r\n\r\nwith open('result_fetch.html', 'w', encoding='utf-8') as result:\r\n result.write(request_fetch.text)\r\n```\r\n\r\n## License\r\n\r\n\u042d\u0442\u043e\u0442 \u043f\u0440\u043e\u0435\u043a\u0442 \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0438 [MIT](https://choosealicense.com/licenses/mit/).\r\n",
"bugtrack_url": null,
"license": null,
"summary": "CurlFetch2Py - \u044d\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0430 Python, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u0430\u044f \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u043a\u043e\u043c\u0430\u043d\u0434 curl \u0438 fetch, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044f \u0438\u0445 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Python",
"version": "0.1",
"project_urls": {
"Homepage": "https://github.com/Yakvenalex/curl_fetch2py"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e16b56e6b96cb79b80014fe5812cb22346c3d0e3b501f34345f7e27ba894ccdb",
"md5": "4486b77f463901dd0cff47f08c6e9dca",
"sha256": "3c76ae58b59c254ef1b94ef01759ee2e0fa3d041eebded2c419302eebf9b2247"
},
"downloads": -1,
"filename": "curl_fetch2py-0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4486b77f463901dd0cff47f08c6e9dca",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 4955,
"upload_time": "2024-07-30T10:04:06",
"upload_time_iso_8601": "2024-07-30T10:04:06.619008Z",
"url": "https://files.pythonhosted.org/packages/e1/6b/56e6b96cb79b80014fe5812cb22346c3d0e3b501f34345f7e27ba894ccdb/curl_fetch2py-0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "040af2b0dc82bc98696a70b589c2fe61b9a552e75d9a2acd48c179b696119ad6",
"md5": "b22acfc3838bddd46ab99cc14b55a9ac",
"sha256": "02973e7d1e0e014eeccb536b36deb76fcfed5c6c1e0051f2a66e0f6f7315fcbe"
},
"downloads": -1,
"filename": "curl_fetch2py-0.1.tar.gz",
"has_sig": false,
"md5_digest": "b22acfc3838bddd46ab99cc14b55a9ac",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 4736,
"upload_time": "2024-07-30T10:04:08",
"upload_time_iso_8601": "2024-07-30T10:04:08.088850Z",
"url": "https://files.pythonhosted.org/packages/04/0a/f2b0dc82bc98696a70b589c2fe61b9a552e75d9a2acd48c179b696119ad6/curl_fetch2py-0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-30 10:04:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Yakvenalex",
"github_project": "curl_fetch2py",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "setuptools",
"specs": []
},
{
"name": "twine",
"specs": []
}
],
"lcname": "curl-fetch2py"
}