API Reference
Complete reference for the EasyScrape API.
Core Functions
scrape()
es.scrape(url: str, **options) -> ScrapeResult
Fetch a URL and return a result object.
Parameters:
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
required |
The URL to fetch |
|
|
|
HTTP method |
|
|
|
Custom headers |
|
|
|
Request timeout in seconds |
|
|
|
Number of retry attempts |
|
|
|
Follow HTTP redirects |
Returns: ScrapeResult object
Example:
result = es.scrape(
"https://example.com",
timeout=10,
headers={"Accept-Language": "en-GB"}
)
async_scrape()
await es.async_scrape(url: str, **options) -> ScrapeResult
Async version of scrape(). Same parameters.
Example:
import asyncio
import easyscrape as es
async def main():
result = await es.async_scrape("https://example.com")
print(result.title())
asyncio.run(main())
ScrapeResult
The result object returned by scrape() and async_scrape().
Properties
Property |
Type |
Description |
|---|---|---|
|
|
HTTP status code |
|
|
Response body as text |
|
|
Response body as bytes |
|
|
Response headers |
|
|
Final URL (after redirects) |
Methods
css(selector: str) -> str | None
Extract the text of the first matching element.
title = result.css("h1")
css_all(selector: str) -> list[str]
Extract text from all matching elements.
items = result.css_all("li.item")
json() -> dict | list
Parse response as JSON.
data = result.json()
title() -> str | None
Get the page title.
main_text() -> str
Extract main content, stripped of navigation and boilerplate.
safe_links() -> list[str]
Get all links, filtered to remove unsafe protocols.
Configuration
Config
from easyscrape import Config
config = Config(
timeout=60,
retries=5,
user_agent="MyBot/1.0"
)
result = es.scrape("https://example.com", config=config)
See Configuration Guide for details.