parse-everything 1.1.6__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- parse_everything-2.0.0/PKG-INFO +141 -0
- parse_everything-2.0.0/README.md +102 -0
- {parse_everything-1.1.6 → parse_everything-2.0.0}/parse_everything/__init__.py +1 -1
- parse_everything-2.0.0/parse_everything/client.py +392 -0
- parse_everything-2.0.0/parse_everything.egg-info/PKG-INFO +141 -0
- {parse_everything-1.1.6 → parse_everything-2.0.0}/parse_everything.egg-info/SOURCES.txt +2 -1
- {parse_everything-1.1.6 → parse_everything-2.0.0}/setup.py +5 -4
- parse_everything-2.0.0/tests/test_client.py +42 -0
- parse_everything-1.1.6/PKG-INFO +0 -140
- parse_everything-1.1.6/README.md +0 -102
- parse_everything-1.1.6/parse_everything/client.py +0 -175
- parse_everything-1.1.6/parse_everything.egg-info/PKG-INFO +0 -140
- {parse_everything-1.1.6 → parse_everything-2.0.0}/parse_everything.egg-info/dependency_links.txt +0 -0
- {parse_everything-1.1.6 → parse_everything-2.0.0}/parse_everything.egg-info/top_level.txt +0 -0
- {parse_everything-1.1.6 → parse_everything-2.0.0}/pyproject.toml +0 -0
- {parse_everything-1.1.6 → parse_everything-2.0.0}/setup.cfg +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: parse-everything
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Official Python SDK for Parse Everything — Anti-Bot Scraping API & Cloud Browser CDP Cluster (browser.parse-everything.com) with 0-credit failure guarantee.
|
|
5
|
+
Home-page: https://parse-everything.com
|
|
6
|
+
Author: Parse Everything
|
|
7
|
+
Author-email: support@parse-everything.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://parse-everything.com
|
|
10
|
+
Project-URL: Cloud Browser, https://browser.parse-everything.com
|
|
11
|
+
Project-URL: Documentation, https://parse-everything.com/docs.php
|
|
12
|
+
Project-URL: Source Code, https://github.com/zenkdom/parse-everything-global
|
|
13
|
+
Project-URL: Bug Tracker, https://github.com/zenkdom/parse-everything-global/issues
|
|
14
|
+
Keywords: cloudflare-bypass,turnstile-solver,akamai-bypass,datadome,web-scraping-api,ja3-spoofing,ja4-fingerprinting,anti-bot,flaresolverr-alternative,zenrows-alternative,scrapingbee-alternative,crawler,web-extraction
|
|
15
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Operating System :: OS Independent
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
Dynamic: author
|
|
29
|
+
Dynamic: author-email
|
|
30
|
+
Dynamic: classifier
|
|
31
|
+
Dynamic: description
|
|
32
|
+
Dynamic: description-content-type
|
|
33
|
+
Dynamic: home-page
|
|
34
|
+
Dynamic: keywords
|
|
35
|
+
Dynamic: license
|
|
36
|
+
Dynamic: project-url
|
|
37
|
+
Dynamic: requires-python
|
|
38
|
+
Dynamic: summary
|
|
39
|
+
|
|
40
|
+
# Parse Everything — Python SDK
|
|
41
|
+
|
|
42
|
+
[](https://pypi.org/project/parse-everything/)
|
|
43
|
+
[](https://parse-everything.com)
|
|
44
|
+
[](https://browser.parse-everything.com)
|
|
45
|
+
[](https://pypi.org/project/parse-everything/)
|
|
46
|
+
|
|
47
|
+
Official lightweight Python client for [Parse Everything](https://parse-everything.com) & [Cloud Browser](https://browser.parse-everything.com) — Enterprise Web Scraping API and Remote Headless Chromium CDP Cluster.
|
|
48
|
+
|
|
49
|
+
- **Fast TLS Core (`render_js=False`)**: `10 credits` per HTTP 200–399 extraction.
|
|
50
|
+
- **Full Chromium Render (`render_js=True`) / Cloud Browser CDP & `/v1/page/scrape`**: `50 credits` per successful extraction or CDP session attach.
|
|
51
|
+
- **Zero-Risk Policy**: Failed, blocked, or unreachable requests always cost **0 credits**.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Quick Install
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install parse-everything
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
*(Zero heavy external dependencies. Uses Python standard library.)*
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Usage Examples
|
|
66
|
+
|
|
67
|
+
### 1. Single URL Scraping (`/api/v1/extract`)
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from parse_everything import ParseEverything
|
|
71
|
+
|
|
72
|
+
client = ParseEverything(api_key="pe_live_YOUR_API_KEY")
|
|
73
|
+
|
|
74
|
+
result = client.scrape(
|
|
75
|
+
target_url="https://parse-everything.com/demo/cloudflare",
|
|
76
|
+
country_code="US",
|
|
77
|
+
render_js=True,
|
|
78
|
+
selectors={"heading": "h1", "price": ".price"},
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
print("HTTP Status:", result["data"]["http_status"])
|
|
82
|
+
print("Title:", result["data"]["page_title"])
|
|
83
|
+
print("Selectors:", result["data"]["selectors_data"])
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 2. Clean Text Extraction (`cleaned_text`)
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
result = client.scrape(
|
|
90
|
+
target_url="https://example.com/article",
|
|
91
|
+
extract_text=True,
|
|
92
|
+
render_js=False, # Fast 10-credit TLS mode
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
print(result["data"]["cleaned_text"])
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 3. Cloud Browser: One-Shot Render & Playwright CDP (`browser.parse-everything.com`)
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
# Option A: Direct REST browser render (/v1/page/scrape)
|
|
102
|
+
page = client.scrape_browser(
|
|
103
|
+
url="https://example.com",
|
|
104
|
+
wait_for_selector="h1",
|
|
105
|
+
extract_text=True,
|
|
106
|
+
)
|
|
107
|
+
print(page["page_title"], page["cleaned_text"])
|
|
108
|
+
|
|
109
|
+
# Option B: Connect Playwright Sync/Async via WebSocket CDP
|
|
110
|
+
cdp_ws = client.cdp_url(stealth=True, persistent=False)
|
|
111
|
+
# -> pass cdp_ws into playwright: p.chromium.connect_over_cdp(cdp_ws)
|
|
112
|
+
|
|
113
|
+
# Option C: Managed named session lifecycle
|
|
114
|
+
sess = client.create_browser_session(session_id="my-profile-1", persistent=True, stealth=True)
|
|
115
|
+
print("Attach CDP:", client.cdp_url(session_id=sess["sessionId"]))
|
|
116
|
+
client.close_browser_session(sess["sessionId"])
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 4. Asynchronous Batch Scraping (Up to 100 URLs)
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
batch_job = client.batch(
|
|
123
|
+
target_urls=[
|
|
124
|
+
"https://example.com/page1",
|
|
125
|
+
"https://example.com/page2",
|
|
126
|
+
],
|
|
127
|
+
webhook_url="https://your-server.com/webhooks/parse",
|
|
128
|
+
)
|
|
129
|
+
status = client.get_batch(batch_job["batch_id"])
|
|
130
|
+
print(f"Progress: {status['progress_percent']}%")
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### 5. Verify Outbound Webhook Signatures (`X-Parse-Signature`)
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
is_valid = ParseEverything.verify_webhook_signature(
|
|
137
|
+
raw_body=request_body_bytes,
|
|
138
|
+
header_signature=request_headers.get("X-Parse-Signature", ""),
|
|
139
|
+
webhook_secret="whsec_your_secret",
|
|
140
|
+
)
|
|
141
|
+
```
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Parse Everything — Python SDK
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/parse-everything/)
|
|
4
|
+
[](https://parse-everything.com)
|
|
5
|
+
[](https://browser.parse-everything.com)
|
|
6
|
+
[](https://pypi.org/project/parse-everything/)
|
|
7
|
+
|
|
8
|
+
Official lightweight Python client for [Parse Everything](https://parse-everything.com) & [Cloud Browser](https://browser.parse-everything.com) — Enterprise Web Scraping API and Remote Headless Chromium CDP Cluster.
|
|
9
|
+
|
|
10
|
+
- **Fast TLS Core (`render_js=False`)**: `10 credits` per HTTP 200–399 extraction.
|
|
11
|
+
- **Full Chromium Render (`render_js=True`) / Cloud Browser CDP & `/v1/page/scrape`**: `50 credits` per successful extraction or CDP session attach.
|
|
12
|
+
- **Zero-Risk Policy**: Failed, blocked, or unreachable requests always cost **0 credits**.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Quick Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install parse-everything
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
*(Zero heavy external dependencies. Uses Python standard library.)*
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Usage Examples
|
|
27
|
+
|
|
28
|
+
### 1. Single URL Scraping (`/api/v1/extract`)
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from parse_everything import ParseEverything
|
|
32
|
+
|
|
33
|
+
client = ParseEverything(api_key="pe_live_YOUR_API_KEY")
|
|
34
|
+
|
|
35
|
+
result = client.scrape(
|
|
36
|
+
target_url="https://parse-everything.com/demo/cloudflare",
|
|
37
|
+
country_code="US",
|
|
38
|
+
render_js=True,
|
|
39
|
+
selectors={"heading": "h1", "price": ".price"},
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
print("HTTP Status:", result["data"]["http_status"])
|
|
43
|
+
print("Title:", result["data"]["page_title"])
|
|
44
|
+
print("Selectors:", result["data"]["selectors_data"])
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. Clean Text Extraction (`cleaned_text`)
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
result = client.scrape(
|
|
51
|
+
target_url="https://example.com/article",
|
|
52
|
+
extract_text=True,
|
|
53
|
+
render_js=False, # Fast 10-credit TLS mode
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
print(result["data"]["cleaned_text"])
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 3. Cloud Browser: One-Shot Render & Playwright CDP (`browser.parse-everything.com`)
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
# Option A: Direct REST browser render (/v1/page/scrape)
|
|
63
|
+
page = client.scrape_browser(
|
|
64
|
+
url="https://example.com",
|
|
65
|
+
wait_for_selector="h1",
|
|
66
|
+
extract_text=True,
|
|
67
|
+
)
|
|
68
|
+
print(page["page_title"], page["cleaned_text"])
|
|
69
|
+
|
|
70
|
+
# Option B: Connect Playwright Sync/Async via WebSocket CDP
|
|
71
|
+
cdp_ws = client.cdp_url(stealth=True, persistent=False)
|
|
72
|
+
# -> pass cdp_ws into playwright: p.chromium.connect_over_cdp(cdp_ws)
|
|
73
|
+
|
|
74
|
+
# Option C: Managed named session lifecycle
|
|
75
|
+
sess = client.create_browser_session(session_id="my-profile-1", persistent=True, stealth=True)
|
|
76
|
+
print("Attach CDP:", client.cdp_url(session_id=sess["sessionId"]))
|
|
77
|
+
client.close_browser_session(sess["sessionId"])
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 4. Asynchronous Batch Scraping (Up to 100 URLs)
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
batch_job = client.batch(
|
|
84
|
+
target_urls=[
|
|
85
|
+
"https://example.com/page1",
|
|
86
|
+
"https://example.com/page2",
|
|
87
|
+
],
|
|
88
|
+
webhook_url="https://your-server.com/webhooks/parse",
|
|
89
|
+
)
|
|
90
|
+
status = client.get_batch(batch_job["batch_id"])
|
|
91
|
+
print(f"Progress: {status['progress_percent']}%")
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 5. Verify Outbound Webhook Signatures (`X-Parse-Signature`)
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
is_valid = ParseEverything.verify_webhook_signature(
|
|
98
|
+
raw_body=request_body_bytes,
|
|
99
|
+
header_signature=request_headers.get("X-Parse-Signature", ""),
|
|
100
|
+
webhook_secret="whsec_your_secret",
|
|
101
|
+
)
|
|
102
|
+
```
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
import hmac
|
|
3
|
+
import json
|
|
4
|
+
import urllib.error
|
|
5
|
+
import urllib.parse
|
|
6
|
+
import urllib.request
|
|
7
|
+
from typing import Any, Dict, List, Optional, Tuple, Union
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ParseEverythingError(Exception):
|
|
11
|
+
"""Base exception for Parse Everything API errors."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, message: str, status_code: Optional[int] = None, response_body: Optional[str] = None):
|
|
14
|
+
super().__init__(message)
|
|
15
|
+
self.status_code = status_code
|
|
16
|
+
self.response_body = response_body
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ParseEverything:
|
|
20
|
+
"""
|
|
21
|
+
Official Python client for Parse Everything (Scraping API + Cloud Browser Cluster).
|
|
22
|
+
|
|
23
|
+
Usage:
|
|
24
|
+
from parse_everything import ParseEverything
|
|
25
|
+
client = ParseEverything(api_key="pe_live_...")
|
|
26
|
+
res = client.scrape("https://example.com")
|
|
27
|
+
print(res["data"]["page_title"])
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
USER_AGENT = "ParseEverything-PythonSDK/2.0.0"
|
|
31
|
+
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
api_key: str,
|
|
35
|
+
base_url: str = "https://parse-everything.com",
|
|
36
|
+
browser_url: str = "https://browser.parse-everything.com",
|
|
37
|
+
):
|
|
38
|
+
if not api_key or not str(api_key).strip():
|
|
39
|
+
raise ValueError("api_key is required. Get 10,000 free credits at https://parse-everything.com")
|
|
40
|
+
self.api_key = str(api_key).strip()
|
|
41
|
+
self.base_url = base_url.rstrip("/")
|
|
42
|
+
self.browser_url = browser_url.rstrip("/")
|
|
43
|
+
|
|
44
|
+
def _request(
|
|
45
|
+
self,
|
|
46
|
+
url: str,
|
|
47
|
+
method: str = "GET",
|
|
48
|
+
payload: Optional[Dict[str, Any]] = None,
|
|
49
|
+
timeout: int = 45,
|
|
50
|
+
error_prefix: str = "API Error",
|
|
51
|
+
) -> Dict[str, Any]:
|
|
52
|
+
headers = {
|
|
53
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
54
|
+
"User-Agent": self.USER_AGENT,
|
|
55
|
+
"Accept": "application/json",
|
|
56
|
+
}
|
|
57
|
+
data_bytes = None
|
|
58
|
+
if payload is not None:
|
|
59
|
+
headers["Content-Type"] = "application/json"
|
|
60
|
+
data_bytes = json.dumps(payload).encode("utf-8")
|
|
61
|
+
|
|
62
|
+
req = urllib.request.Request(url, data=data_bytes, headers=headers, method=method.upper())
|
|
63
|
+
try:
|
|
64
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
65
|
+
raw = resp.read().decode("utf-8", errors="replace")
|
|
66
|
+
return json.loads(raw) if raw else {}
|
|
67
|
+
except urllib.error.HTTPError as e:
|
|
68
|
+
body_resp = e.read().decode("utf-8", errors="replace")
|
|
69
|
+
try:
|
|
70
|
+
err_json = json.loads(body_resp)
|
|
71
|
+
msg = (
|
|
72
|
+
err_json.get("reason")
|
|
73
|
+
or err_json.get("message")
|
|
74
|
+
or err_json.get("error")
|
|
75
|
+
or err_json.get("detail")
|
|
76
|
+
or str(e)
|
|
77
|
+
)
|
|
78
|
+
except Exception:
|
|
79
|
+
msg = body_resp or str(e)
|
|
80
|
+
raise ParseEverythingError(f"{error_prefix} ({e.code}): {msg}", status_code=e.code, response_body=body_resp)
|
|
81
|
+
except Exception as e:
|
|
82
|
+
raise ParseEverythingError(f"Request failed: {str(e)}")
|
|
83
|
+
|
|
84
|
+
# ------------------------------------------------------------------
|
|
85
|
+
# Scraping REST API (parse-everything.com)
|
|
86
|
+
# ------------------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
def scrape(
|
|
89
|
+
self,
|
|
90
|
+
target_url: str,
|
|
91
|
+
render_js: bool = True,
|
|
92
|
+
bypass_cloudflare: Optional[bool] = None,
|
|
93
|
+
bypass_akamai: Optional[bool] = None,
|
|
94
|
+
country_code: str = "US",
|
|
95
|
+
extract_text: bool = False,
|
|
96
|
+
selectors: Optional[Dict[str, str]] = None,
|
|
97
|
+
custom_headers: Optional[Dict[str, str]] = None,
|
|
98
|
+
cookies: Optional[Dict[str, str]] = None,
|
|
99
|
+
proxy: Optional[str] = None,
|
|
100
|
+
timeout: int = 40,
|
|
101
|
+
method: str = "GET",
|
|
102
|
+
body: Optional[Any] = None,
|
|
103
|
+
post_data: Optional[Any] = None,
|
|
104
|
+
auto_detect: bool = True,
|
|
105
|
+
wait_for_selector: Optional[str] = None,
|
|
106
|
+
session_id: Optional[str] = None,
|
|
107
|
+
use_session: Optional[bool] = None,
|
|
108
|
+
fresh_session: Optional[bool] = None,
|
|
109
|
+
webhook_url: Optional[str] = None,
|
|
110
|
+
) -> Dict[str, Any]:
|
|
111
|
+
"""
|
|
112
|
+
Extract HTML, cleaned text, or CSS selectors from any target URL.
|
|
113
|
+
TLS core costs 10 credits; render_js / Turnstile costs 50 credits; failures cost 0 credits.
|
|
114
|
+
"""
|
|
115
|
+
target_method = (method or "GET").strip().upper()
|
|
116
|
+
target_body = body if body is not None else post_data
|
|
117
|
+
|
|
118
|
+
payload: Dict[str, Any] = {
|
|
119
|
+
"target_url": target_url,
|
|
120
|
+
"method": target_method,
|
|
121
|
+
"render_js": render_js,
|
|
122
|
+
"auto_detect": auto_detect,
|
|
123
|
+
"country_code": country_code,
|
|
124
|
+
"extract_text": extract_text,
|
|
125
|
+
"timeout": timeout,
|
|
126
|
+
}
|
|
127
|
+
if bypass_cloudflare is not None:
|
|
128
|
+
payload["bypass_cloudflare"] = bypass_cloudflare
|
|
129
|
+
if bypass_akamai is not None:
|
|
130
|
+
payload["bypass_akamai"] = bypass_akamai
|
|
131
|
+
if target_body is not None:
|
|
132
|
+
payload["body"] = target_body
|
|
133
|
+
if selectors:
|
|
134
|
+
payload["selectors"] = selectors
|
|
135
|
+
if wait_for_selector:
|
|
136
|
+
payload["wait_for_selector"] = wait_for_selector
|
|
137
|
+
if custom_headers:
|
|
138
|
+
payload["custom_headers"] = custom_headers
|
|
139
|
+
if cookies:
|
|
140
|
+
payload["cookies"] = cookies
|
|
141
|
+
if proxy:
|
|
142
|
+
payload["proxy"] = proxy
|
|
143
|
+
if session_id:
|
|
144
|
+
payload["session_id"] = session_id
|
|
145
|
+
if use_session is not None:
|
|
146
|
+
payload["use_session"] = use_session
|
|
147
|
+
if fresh_session is not None:
|
|
148
|
+
payload["fresh_session"] = fresh_session
|
|
149
|
+
if webhook_url:
|
|
150
|
+
payload["webhook_url"] = webhook_url
|
|
151
|
+
|
|
152
|
+
return self._request(
|
|
153
|
+
f"{self.base_url}/api/v1/extract",
|
|
154
|
+
method="POST",
|
|
155
|
+
payload=payload,
|
|
156
|
+
timeout=timeout + 10,
|
|
157
|
+
error_prefix="API Error",
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
def get(self, url: str, **kwargs: Any) -> Dict[str, Any]:
|
|
161
|
+
"""Convenience helper for GET extraction."""
|
|
162
|
+
return self.scrape(target_url=url, method="GET", **kwargs)
|
|
163
|
+
|
|
164
|
+
def post(
|
|
165
|
+
self, url: str, data: Optional[Any] = None, json_body: Optional[Any] = None, **kwargs: Any
|
|
166
|
+
) -> Dict[str, Any]:
|
|
167
|
+
"""Convenience helper for POST extraction with body forwarding."""
|
|
168
|
+
payload_body = json_body if json_body is not None else data
|
|
169
|
+
return self.scrape(target_url=url, method="POST", body=payload_body, **kwargs)
|
|
170
|
+
|
|
171
|
+
def put(
|
|
172
|
+
self, url: str, data: Optional[Any] = None, json_body: Optional[Any] = None, **kwargs: Any
|
|
173
|
+
) -> Dict[str, Any]:
|
|
174
|
+
"""Convenience helper for PUT extraction with body forwarding."""
|
|
175
|
+
payload_body = json_body if json_body is not None else data
|
|
176
|
+
return self.scrape(target_url=url, method="PUT", body=payload_body, **kwargs)
|
|
177
|
+
|
|
178
|
+
def delete(self, url: str, **kwargs: Any) -> Dict[str, Any]:
|
|
179
|
+
"""Convenience helper for DELETE extraction."""
|
|
180
|
+
return self.scrape(target_url=url, method="DELETE", **kwargs)
|
|
181
|
+
|
|
182
|
+
def batch(
|
|
183
|
+
self,
|
|
184
|
+
target_urls: List[str],
|
|
185
|
+
render_js: bool = True,
|
|
186
|
+
country_code: str = "US",
|
|
187
|
+
webhook_url: Optional[str] = None,
|
|
188
|
+
) -> Dict[str, Any]:
|
|
189
|
+
"""Submit a batch of up to 100 URLs for asynchronous extraction."""
|
|
190
|
+
payload: Dict[str, Any] = {
|
|
191
|
+
"target_urls": target_urls,
|
|
192
|
+
"render_js": render_js,
|
|
193
|
+
"country_code": country_code,
|
|
194
|
+
}
|
|
195
|
+
if webhook_url:
|
|
196
|
+
payload["webhook_url"] = webhook_url
|
|
197
|
+
|
|
198
|
+
return self._request(
|
|
199
|
+
f"{self.base_url}/api/v1/batch",
|
|
200
|
+
method="POST",
|
|
201
|
+
payload=payload,
|
|
202
|
+
timeout=30,
|
|
203
|
+
error_prefix="Batch Error",
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
def get_batch(self, batch_id: str) -> Dict[str, Any]:
|
|
207
|
+
"""Poll progress and results for a batch job."""
|
|
208
|
+
return self._request(
|
|
209
|
+
f"{self.base_url}/api/v1/batch/{urllib.parse.quote(batch_id, safe='')}",
|
|
210
|
+
method="GET",
|
|
211
|
+
timeout=20,
|
|
212
|
+
error_prefix="Batch poll failed",
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
def get_batch_status(self, batch_id: str) -> Dict[str, Any]:
|
|
216
|
+
"""Alias for get_batch()."""
|
|
217
|
+
return self.get_batch(batch_id)
|
|
218
|
+
|
|
219
|
+
# ------------------------------------------------------------------
|
|
220
|
+
# Cloud Browser & CDP Cluster (browser.parse-everything.com)
|
|
221
|
+
# ------------------------------------------------------------------
|
|
222
|
+
|
|
223
|
+
def cdp_url(
|
|
224
|
+
self,
|
|
225
|
+
session_id: Optional[str] = None,
|
|
226
|
+
stealth: Optional[bool] = None,
|
|
227
|
+
persistent: Optional[bool] = None,
|
|
228
|
+
proxy: Optional[str] = None,
|
|
229
|
+
) -> str:
|
|
230
|
+
"""Build WebSocket CDP connection URL for Playwright/Puppeteer."""
|
|
231
|
+
ws_base = (
|
|
232
|
+
self.browser_url.replace("https://", "wss://", 1).replace("http://", "ws://", 1)
|
|
233
|
+
)
|
|
234
|
+
path = f"/cdp/{urllib.parse.quote(session_id, safe='')}" if session_id else "/connect"
|
|
235
|
+
params: List[Tuple[str, str]] = [("token", self.api_key)]
|
|
236
|
+
if stealth is not None:
|
|
237
|
+
params.append(("stealth", "true" if stealth else "false"))
|
|
238
|
+
if persistent is not None:
|
|
239
|
+
params.append(("persistent", "true" if persistent else "false"))
|
|
240
|
+
if proxy:
|
|
241
|
+
params.append(("proxy", proxy))
|
|
242
|
+
return f"{ws_base}{path}?{urllib.parse.urlencode(params)}"
|
|
243
|
+
|
|
244
|
+
def create_browser_session(
|
|
245
|
+
self,
|
|
246
|
+
session_id: Optional[str] = None,
|
|
247
|
+
proxy_server: Optional[str] = None,
|
|
248
|
+
proxy_bypass_list: Optional[str] = None,
|
|
249
|
+
persistent: Optional[bool] = None,
|
|
250
|
+
stealth: Optional[bool] = None,
|
|
251
|
+
headless: Optional[bool] = None,
|
|
252
|
+
window_size: Optional[Dict[str, int]] = None,
|
|
253
|
+
user_agent: Optional[str] = None,
|
|
254
|
+
extra_args: Optional[List[str]] = None,
|
|
255
|
+
) -> Dict[str, Any]:
|
|
256
|
+
"""Spawn or claim a pre-warmed remote Chromium CDP session."""
|
|
257
|
+
payload: Dict[str, Any] = {}
|
|
258
|
+
if session_id:
|
|
259
|
+
payload["sessionId"] = session_id
|
|
260
|
+
if proxy_server:
|
|
261
|
+
payload["proxyServer"] = proxy_server
|
|
262
|
+
if proxy_bypass_list:
|
|
263
|
+
payload["proxyBypassList"] = proxy_bypass_list
|
|
264
|
+
if persistent is not None:
|
|
265
|
+
payload["persistent"] = persistent
|
|
266
|
+
if stealth is not None:
|
|
267
|
+
payload["stealth"] = stealth
|
|
268
|
+
if headless is not None:
|
|
269
|
+
payload["headless"] = headless
|
|
270
|
+
if window_size is not None:
|
|
271
|
+
payload["windowSize"] = window_size
|
|
272
|
+
if user_agent:
|
|
273
|
+
payload["userAgent"] = user_agent
|
|
274
|
+
if extra_args:
|
|
275
|
+
payload["extraArgs"] = extra_args
|
|
276
|
+
|
|
277
|
+
return self._request(
|
|
278
|
+
f"{self.browser_url}/v1/sessions",
|
|
279
|
+
method="POST",
|
|
280
|
+
payload=payload,
|
|
281
|
+
timeout=30,
|
|
282
|
+
error_prefix="Browser Session Error",
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
def list_browser_sessions(self) -> Dict[str, Any]:
|
|
286
|
+
"""List active Cloud Browser sessions owned by this account."""
|
|
287
|
+
return self._request(
|
|
288
|
+
f"{self.browser_url}/v1/sessions",
|
|
289
|
+
method="GET",
|
|
290
|
+
timeout=15,
|
|
291
|
+
error_prefix="Browser Session List Error",
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
def get_browser_session(self, session_id: str) -> Dict[str, Any]:
|
|
295
|
+
"""Fetch live stats for an owned Cloud Browser session."""
|
|
296
|
+
return self._request(
|
|
297
|
+
f"{self.browser_url}/v1/sessions/{urllib.parse.quote(session_id, safe='')}",
|
|
298
|
+
method="GET",
|
|
299
|
+
timeout=15,
|
|
300
|
+
error_prefix="Browser Session Error",
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
def close_browser_session(self, session_id: str) -> Dict[str, Any]:
|
|
304
|
+
"""Terminate an owned Cloud Browser session."""
|
|
305
|
+
return self._request(
|
|
306
|
+
f"{self.browser_url}/v1/sessions/{urllib.parse.quote(session_id, safe='')}",
|
|
307
|
+
method="DELETE",
|
|
308
|
+
timeout=15,
|
|
309
|
+
error_prefix="Browser Session Close Error",
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
def scrape_browser(
|
|
313
|
+
self,
|
|
314
|
+
url: str,
|
|
315
|
+
timeout: int = 30000,
|
|
316
|
+
extract_text: bool = True,
|
|
317
|
+
wait_for_selector: Optional[str] = None,
|
|
318
|
+
selectors: Optional[Dict[str, str]] = None,
|
|
319
|
+
proxy_server: Optional[str] = None,
|
|
320
|
+
stealth: Optional[bool] = None,
|
|
321
|
+
) -> Dict[str, Any]:
|
|
322
|
+
"""
|
|
323
|
+
Execute a one-shot headless Chromium render on browser.parse-everything.com (/v1/page/scrape).
|
|
324
|
+
Costs 50 credits on HTTP 200-399, 0 credits on error/SSRF block.
|
|
325
|
+
"""
|
|
326
|
+
payload: Dict[str, Any] = {
|
|
327
|
+
"url": url,
|
|
328
|
+
"timeout": timeout,
|
|
329
|
+
"extractText": extract_text,
|
|
330
|
+
}
|
|
331
|
+
if wait_for_selector:
|
|
332
|
+
payload["waitForSelector"] = wait_for_selector
|
|
333
|
+
if selectors:
|
|
334
|
+
payload["selectors"] = selectors
|
|
335
|
+
if proxy_server:
|
|
336
|
+
payload["proxyServer"] = proxy_server
|
|
337
|
+
if stealth is not None:
|
|
338
|
+
payload["stealth"] = stealth
|
|
339
|
+
|
|
340
|
+
return self._request(
|
|
341
|
+
f"{self.browser_url}/v1/page/scrape",
|
|
342
|
+
method="POST",
|
|
343
|
+
payload=payload,
|
|
344
|
+
timeout=max(35, int(timeout / 1000) + 15),
|
|
345
|
+
error_prefix="Browser Scrape Error",
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
# ------------------------------------------------------------------
|
|
349
|
+
# Unified Account Settings, Logs & Webhooks
|
|
350
|
+
# ------------------------------------------------------------------
|
|
351
|
+
|
|
352
|
+
def get_account_settings(self) -> Dict[str, Any]:
|
|
353
|
+
"""Read unified account profile & Cloud Browser default launch parameters."""
|
|
354
|
+
return self._request(
|
|
355
|
+
f"{self.base_url}/api/settings.php",
|
|
356
|
+
method="GET",
|
|
357
|
+
timeout=15,
|
|
358
|
+
error_prefix="Settings Error",
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
def update_account_settings(self, settings: Dict[str, Any]) -> Dict[str, Any]:
|
|
362
|
+
"""Update unified account profile & Cloud Browser default launch parameters."""
|
|
363
|
+
return self._request(
|
|
364
|
+
f"{self.base_url}/api/settings.php",
|
|
365
|
+
method="POST",
|
|
366
|
+
payload=settings,
|
|
367
|
+
timeout=15,
|
|
368
|
+
error_prefix="Settings Update Error",
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
def get_logs(self, limit: int = 30, offset: int = 0) -> Dict[str, Any]:
|
|
372
|
+
"""Fetch paginated request & Cloud Browser execution logs."""
|
|
373
|
+
query = urllib.parse.urlencode({"limit": limit, "offset": offset})
|
|
374
|
+
return self._request(
|
|
375
|
+
f"{self.base_url}/api/v1/logs.php?{query}",
|
|
376
|
+
method="GET",
|
|
377
|
+
timeout=15,
|
|
378
|
+
error_prefix="Logs Error",
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
@staticmethod
|
|
382
|
+
def verify_webhook_signature(
|
|
383
|
+
raw_body: Union[bytes, str], header_signature: str, webhook_secret: str
|
|
384
|
+
) -> bool:
|
|
385
|
+
"""Timing-safe HMAC-SHA256 verification for X-Parse-Signature webhooks."""
|
|
386
|
+
if not header_signature or not webhook_secret:
|
|
387
|
+
return False
|
|
388
|
+
body_bytes = raw_body.encode("utf-8") if isinstance(raw_body, str) else raw_body
|
|
389
|
+
expected = "sha256=" + hmac.new(
|
|
390
|
+
webhook_secret.encode("utf-8"), body_bytes, hashlib.sha256
|
|
391
|
+
).hexdigest()
|
|
392
|
+
return hmac.compare_digest(expected, header_signature.strip())
|