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

url

str

required

The URL to fetch

method

str

"GET"

HTTP method

headers

dict

None

Custom headers

timeout

float

30.0

Request timeout in seconds

retries

int

3

Number of retry attempts

follow_redirects

bool

True

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

status_code

int

HTTP status code

text

str

Response body as text

content

bytes

Response body as bytes

headers

dict

Response headers

url

str

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.


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.