Skip to main content

Overview

Scrapling provides powerful methods to extract data from HTML elements. Whether you need text content, HTML markup, attributes, or structured data, Scrapling has you covered.

Basic Extraction

get()

Serialize an element to a string.
For text nodes, returns the text value. For HTML elements, returns the outer HTML.

getall()

Extract data from all matched elements.
For Selector (single element): Returns a single-element list containing the element’s serialized string. For Selectors (multiple elements): Serializes all elements and returns as a TextHandlers list.

extract() and extract_first()

Aliases for backward compatibility with other scraping libraries.

Text Extraction

text

Get the direct text content of an element.
Returns the text content of the element. For text nodes, returns the text value. For HTML elements, returns the element’s direct text (not including children).

get_all_text()

Get all text from an element and its descendants.
str
default:"\\n"
Strings will be concatenated using this separator
bool
default:"false"
If True, strings will be stripped before being concatenated
Tuple
default:"('script', 'style')"
A tuple of tag names to ignore when extracting text
bool
default:"true"
If enabled, elements with text-content that is empty or only whitespaces will be ignored

HTML Extraction

html_content

Get the inner HTML of an element.
Returns the inner HTML code of the element.

prettify()

Get a formatted, prettified version of the HTML.
Returns a prettified version of the element’s inner HTML code with proper indentation.

body

Get the raw body without processing.
Returns the raw body of the current Selector without any processing. Useful for binary and non-HTML requests.

Attribute Extraction

attrib

Access element attributes.
Returns an AttributesHandler containing all attributes of the element.

Element Access with []

Direct attribute access using bracket notation.

Check Attribute Existence

Tag Information

tag

Get the tag name of an element.

has_class()

Check if an element has a specific class.
str
required
The class name to check for

Regex Extraction

Extract data using regular expressions.

re()

Apply regex to element text and return all matches.
str | Pattern[str]
required
Can be either a compiled regular expression or a string
bool
default:"true"
If enabled, character entity references are replaced by their corresponding character
bool
default:"false"
If enabled, ignores all whitespaces and consecutive spaces while matching
bool
default:"true"
If disabled, the function will ignore letter case while matching

re_first()

Apply regex and return the first match.
Any
default:"None"
The default value to be returned if there is no match

JSON Extraction

Extract and parse JSON data.

json()

Parse element content as JSON.
Returns a parsed JSON response if the content is valid JSON, otherwise raises an error.

URL Handling

urljoin()

Join relative URLs with the page’s base URL.
str
required
The relative URL to join with the page’s URL

Practical Examples

Extract Product Information

Extract Article Content

Extract Table Data

Extract Contact Information