Skip to content

Commit

Permalink
Change docs format to rst (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
perklet authored Feb 22, 2024
1 parent 537d319 commit f3ee8ad
Show file tree
Hide file tree
Showing 33 changed files with 888 additions and 105 deletions.
9 changes: 7 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ build:
os: ubuntu-22.04
tools:
python: "3.11"
mkdocs:
configuration: mkdocs.yml

# Optionally declare the Python requirements required to build your docs
python:
install:
- requirements: docs/requirements.txt

sphinx:
configuration: docs/conf.py

formats:
- pdf
- epub
10 changes: 10 additions & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ print(body.decode())

Yescaptcha 是一个可以识别 Cloudflare 盾的接口,直接返回识别完成的 Cookies (`cf_clearance` 等) [点此](https://yescaptcha.com/i/stfnIO)注册:https://yescaptcha.com/i/stfnIO

## [赞助商] ScrapeNinja

<a href="https://scrapeninja.net?utm_source=github&utm_medium=banner&utm_campaign=cffi" target="_blank"><img src="https://scrapeninja.net/img/logo_with_text_new5.svg" alt="Scrape Ninja" width="149"></a>

[ScrapeNinja](https://scrapeninja.net?utm_source=github&utm_medium=banner&utm_campaign=cffi) 是一个网络采集 API,它有两个引擎:极速版,性能
较好,可以模拟 TLS 指纹;和通用版,使用浏览器。

ScrapeNinja 帮你解决无头浏览器,代理,超时,重试,并且负责数据抽取,这样你可以直接拿到
JSON 数据。在所有的订阅方案中,切换代理都是直接可用的。

## 赞助

<img src="assets/alipay.jpg" style="width: 512px;" />
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ website for no obvious reason, you can give this package a try.
## Features

- Supports JA3/TLS and http2 fingerprints impersonation.
- Much faster than requests/httpx, on par with aiohttp/pycurl, see [benchmarks](https:/yifeikong/curl_cffi/tree/master/benchmark).
- Much faster than requests/httpx, on par with aiohttp/pycurl, see [benchmarks](https:/yifeikong/curl_cffi/tree/main/benchmark).
- Mimics requests API, no need to learn another one.
- Pre-compiled, so you don't have to compile on your machine.
- Supports `asyncio` with proxy rotation on each request.
Expand All @@ -32,7 +32,7 @@ website for no obvious reason, you can give this package a try.

pip install curl_cffi --upgrade

This should work on Linux(x86_64/aarch64), macOS(Intel/Apple Silicon) and Windows(amd64).
This should work on Linux, macOS and Windows out of the box.
If it does not work on you platform, you may need to compile and install `curl-impersonate`
first and set some environment variables like `LD_LIBRARY_PATH`.

Expand Down Expand Up @@ -198,6 +198,17 @@ If you are using scrapy, check out these middlewares:

Yescaptcha is a proxy service that bypasses Cloudflare and uses the API interface to obtain verified cookies (e.g. `cf_clearance`). Click [here](https://yescaptcha.com/i/stfnIO) to register: https://yescaptcha.com/i/stfnIO

## [Sponsor] ScrapeNinja

<a href="https://scrapeninja.net?utm_source=github&utm_medium=banner&utm_campaign=cffi" target="_blank"><img src="https://scrapeninja.net/img/logo_with_text_new5.svg" alt="Scrape Ninja" width="149"></a>

[ScrapeNinja](https://scrapeninja.net?utm_source=github&utm_medium=banner&utm_campaign=cffi) is a web scraping API with two engines: fast, with high performance and TLS
fingerprint; and slower with a real browser under the hood.

ScrapeNinja handles headless browsers, proxies, timeouts, retries, and helps with data
extraction, so you can just get the data in JSON. Rotating proxies are available out of
the box on all subscription plans.

## Sponsor

<a href="https://buymeacoffee.com/yifei" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>
9 changes: 5 additions & 4 deletions curl_cffi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
__all__ = [
"Curl",
"AsyncCurl",
"CurlMime",
"CurlError",
"CurlInfo",
"CurlOpt",
"CurlMOpt",
"CurlMime",
"CurlECode",
"CurlHttpVersion",
"CurlError",
"AsyncCurl",
"CurlWsFlag",
"ffi",
"lib",
]
Expand All @@ -16,7 +17,7 @@
# This line includes _wrapper.so into the wheel
from ._wrapper import ffi, lib # type: ignore

from .const import CurlInfo, CurlMOpt, CurlOpt, CurlECode, CurlHttpVersion
from .const import CurlInfo, CurlMOpt, CurlOpt, CurlECode, CurlHttpVersion, CurlWsFlag
from .curl import Curl, CurlError, CurlMime
from .aio import AsyncCurl

Expand Down
9 changes: 7 additions & 2 deletions curl_cffi/aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ class AsyncCurl:
"""Wrapper around curl_multi handle to provide asyncio support. It uses the libcurl
socket_action APIs."""

def __init__(self, cacert: str = DEFAULT_CACERT, loop=None):
def __init__(self, cacert: str = "", loop=None):
"""
Parameters:
cacert: CA cert path to use, by default, curl_cffi uses certs from ``certifi``.
loop: EventLoop to use.
"""
self._curlm = lib.curl_multi_init()
self._cacert = cacert
self._cacert = cacert or DEFAULT_CACERT
self._curl2future = {} # curl to future map
self._curl2curl = {} # c curl to Curl
self._sockfds = set() # sockfds
Expand Down
16 changes: 16 additions & 0 deletions curl_cffi/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@


class CurlOpt(IntEnum):
"""``CULROPT_`` constancs extracted from libcurl,
see: https://curl.se/libcurl/c/curl_easy_setopt.html"""

WRITEDATA = 10000 + 1
URL = 10000 + 2
PORT = 0 + 3
Expand Down Expand Up @@ -328,6 +331,9 @@ class CurlOpt(IntEnum):


class CurlInfo(IntEnum):
"""``CURLINFO_`` constancs extracted from libcurl,
see: https://curl.se/libcurl/c/curl_easy_getinfo.html"""

TEXT = 0
EFFECTIVE_URL = 0x100000 + 1
RESPONSE_CODE = 0x200000 + 2
Expand Down Expand Up @@ -396,6 +402,9 @@ class CurlInfo(IntEnum):


class CurlMOpt(IntEnum):
"""``CURLMOPT_`` constancs extracted from libcurl,
see: https://curl.se/libcurl/c/curl_multi_setopt.html"""

SOCKETFUNCTION = 20000 + 1
SOCKETDATA = 10000 + 2
PIPELINING = 0 + 3
Expand All @@ -415,6 +424,9 @@ class CurlMOpt(IntEnum):


class CurlECode(IntEnum):
"""``CURLECODE_`` constancs extracted from libcurl,
see: https://curl.se/libcurl/c/libcurl-errors.html"""

OK = 0
UNSUPPORTED_PROTOCOL = 1
FAILED_INIT = 2
Expand Down Expand Up @@ -519,6 +531,8 @@ class CurlECode(IntEnum):


class CurlHttpVersion(IntEnum):
"""``CURL_HTTP_VERSION`` constants extracted from libcurl, see comments for details"""

NONE = 0
V1_0 = 1 # please use HTTP 1.0 in the request */
V1_1 = 2 # please use HTTP 1.1 in the request */
Expand All @@ -529,6 +543,8 @@ class CurlHttpVersion(IntEnum):


class CurlWsFlag(IntEnum):
"""``CURL_WS_FLAG`` constancs extracted from libcurl, see comments for details"""

TEXT = (1<<0)
BINARY = (1<<1)
CONT = (1<<2)
Expand Down
Loading

0 comments on commit f3ee8ad

Please sign in to comment.