webcrawlerapi 2.1.3__tar.gz → 2.1.6__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.
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/PKG-INFO +1 -1
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/setup.py +1 -1
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/tests/test_models.py +1 -1
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/webcrawlerapi/__init__.py +2 -0
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/webcrawlerapi/client.py +26 -0
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/webcrawlerapi/models.py +10 -2
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/webcrawlerapi.egg-info/PKG-INFO +1 -1
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/README.md +0 -0
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/pyproject.toml +0 -0
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/setup.cfg +0 -0
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/tests/__init__.py +0 -0
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/tests/test_client.py +0 -0
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/webcrawlerapi.egg-info/SOURCES.txt +0 -0
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/webcrawlerapi.egg-info/dependency_links.txt +0 -0
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/webcrawlerapi.egg-info/requires.txt +0 -0
- {webcrawlerapi-2.1.3 → webcrawlerapi-2.1.6}/webcrawlerapi.egg-info/top_level.txt +0 -0
|
@@ -428,4 +428,4 @@ class TestJob:
|
|
|
428
428
|
|
|
429
429
|
def test_job_terminal_statuses_constant(self):
|
|
430
430
|
"""Test that TERMINAL_STATUSES constant is correctly defined."""
|
|
431
|
-
assert Job.TERMINAL_STATUSES == {"done", "error", "cancelled"}
|
|
431
|
+
assert Job.TERMINAL_STATUSES == {"done", "error", "cancelled", "canceled"}
|
|
@@ -30,6 +30,7 @@ from .models import (
|
|
|
30
30
|
Job,
|
|
31
31
|
JobItem,
|
|
32
32
|
JobMarkdownResponse,
|
|
33
|
+
MarkdownResponse,
|
|
33
34
|
ScrapeId,
|
|
34
35
|
ScrapeResponse,
|
|
35
36
|
ScrapeResponseError,
|
|
@@ -44,6 +45,7 @@ __all__ = [
|
|
|
44
45
|
"Job",
|
|
45
46
|
"JobItem",
|
|
46
47
|
"JobMarkdownResponse",
|
|
48
|
+
"MarkdownResponse",
|
|
47
49
|
"CrawlResponse",
|
|
48
50
|
"ScrapeId",
|
|
49
51
|
"ScrapeResponse",
|
|
@@ -10,6 +10,7 @@ from .models import (
|
|
|
10
10
|
CrawlResponse,
|
|
11
11
|
Job,
|
|
12
12
|
JobMarkdownResponse,
|
|
13
|
+
MarkdownResponse,
|
|
13
14
|
ScrapeId,
|
|
14
15
|
ScrapeResponse,
|
|
15
16
|
ScrapeResponseError,
|
|
@@ -201,6 +202,31 @@ class WebCrawlerAPI:
|
|
|
201
202
|
self._raise_for_error(response)
|
|
202
203
|
return response.text
|
|
203
204
|
|
|
205
|
+
def markdown(self, url: str) -> MarkdownResponse:
|
|
206
|
+
"""
|
|
207
|
+
Extract cleaned article markdown (main content only) from a webpage.
|
|
208
|
+
|
|
209
|
+
Args:
|
|
210
|
+
url (str): The URL of the webpage to extract the article markdown from
|
|
211
|
+
|
|
212
|
+
Returns:
|
|
213
|
+
MarkdownResponse: Response containing the extracted markdown
|
|
214
|
+
|
|
215
|
+
Raises:
|
|
216
|
+
WebCrawlerApiError: If the API returns an error response
|
|
217
|
+
requests.exceptions.RequestException: If the HTTP request fails
|
|
218
|
+
"""
|
|
219
|
+
response = self.session.post(
|
|
220
|
+
urljoin(self.base_url, "/markdown"),
|
|
221
|
+
json={"url": url},
|
|
222
|
+
)
|
|
223
|
+
if not response.ok:
|
|
224
|
+
self._raise_for_error(response)
|
|
225
|
+
data = response.json()
|
|
226
|
+
return MarkdownResponse(
|
|
227
|
+
success=data.get("success", True), markdown=data.get("markdown")
|
|
228
|
+
)
|
|
229
|
+
|
|
204
230
|
def cancel_job(self, job_id: str) -> Dict[str, str]:
|
|
205
231
|
"""
|
|
206
232
|
Cancel a running job. All items that are not in progress and not done
|
|
@@ -62,6 +62,14 @@ class JobMarkdownResponse:
|
|
|
62
62
|
content_url: str
|
|
63
63
|
|
|
64
64
|
|
|
65
|
+
@dataclass
|
|
66
|
+
class MarkdownResponse:
|
|
67
|
+
"""Response from the markdown endpoint."""
|
|
68
|
+
|
|
69
|
+
success: bool
|
|
70
|
+
markdown: Optional[str] = None
|
|
71
|
+
|
|
72
|
+
|
|
65
73
|
@dataclass
|
|
66
74
|
class ScrapeId:
|
|
67
75
|
"""Response from an asynchronous scrape request."""
|
|
@@ -276,7 +284,7 @@ class JobItem:
|
|
|
276
284
|
class Job:
|
|
277
285
|
"""Represents a crawling job."""
|
|
278
286
|
|
|
279
|
-
TERMINAL_STATUSES = {"done", "error", "cancelled"}
|
|
287
|
+
TERMINAL_STATUSES = {"done", "error", "cancelled", "canceled"}
|
|
280
288
|
|
|
281
289
|
def __init__(self, data: Dict[str, Any]):
|
|
282
290
|
self.id: str = data["id"]
|
|
@@ -309,5 +317,5 @@ class Job:
|
|
|
309
317
|
|
|
310
318
|
@property
|
|
311
319
|
def is_terminal(self) -> bool:
|
|
312
|
-
"""Check if the job is in a terminal state (done, error, or cancelled)."""
|
|
320
|
+
"""Check if the job is in a terminal state (done, error, or cancelled/canceled)."""
|
|
313
321
|
return self.status in self.TERMINAL_STATUSES
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|