Custom Types API Reference¶
Here's the reference information for all custom types of classes Scrapling implemented, with all their parameters, attributes, and methods.
You can import all of them directly like below:
scrapling.core.custom_types.TextHandler
¶
Bases: str
flowchart TD
scrapling.core.custom_types.TextHandler[TextHandler]
click scrapling.core.custom_types.TextHandler href "" "scrapling.core.custom_types.TextHandler"
Extends standard Python string by adding more functionality
__getitem__
¶
split
¶
strip
¶
lstrip
¶
rstrip
¶
capitalize
¶
casefold
¶
center
¶
expandtabs
¶
format
¶
format_map
¶
join
¶
ljust
¶
rjust
¶
swapcase
¶
title
¶
translate
¶
zfill
¶
replace
¶
upper
¶
lower
¶
sort
¶
clean
¶
Return a new version of the string after removing all white spaces and consecutive spaces
Source code in scrapling/core/custom_types.py
get
¶
getall
¶
json
¶
Return JSON response if the response is jsonable otherwise throw error
Source code in scrapling/core/custom_types.py
re
¶
Apply the given regex to the current text and return a list of strings with the matches.
| PARAMETER | DESCRIPTION |
|---|---|
regex
|
Can be either a compiled regular expression or a string.
TYPE:
|
replace_entities
|
If enabled character entity references are replaced by their corresponding character
TYPE:
|
clean_match
|
If enabled, this will ignore all whitespaces and consecutive spaces while matching
TYPE:
|
case_sensitive
|
If disabled, function will set the regex to ignore the letters-case while compiling it
TYPE:
|
check_match
|
Used to quickly check if this regex matches or not without any operations on the results
TYPE:
|
Source code in scrapling/core/custom_types.py
re_first
¶
Apply the given regex to text and return the first match if found, otherwise return the default value.
| PARAMETER | DESCRIPTION |
|---|---|
regex
|
Can be either a compiled regular expression or a string.
TYPE:
|
default
|
The default value to be returned if there is no match
TYPE:
|
replace_entities
|
If enabled character entity references are replaced by their corresponding character
TYPE:
|
clean_match
|
If enabled, this will ignore all whitespaces and consecutive spaces while matching
TYPE:
|
case_sensitive
|
If disabled, function will set the regex to ignore the letters-case while compiling it
TYPE:
|
Source code in scrapling/core/custom_types.py
scrapling.core.custom_types.TextHandlers
¶
Bases: List[TextHandler]
flowchart TD
scrapling.core.custom_types.TextHandlers[TextHandlers]
click scrapling.core.custom_types.TextHandlers href "" "scrapling.core.custom_types.TextHandlers"
The :class:TextHandlers class is a subclass of the builtin List class, which provides a few additional methods.
__getitem__
¶
Source code in scrapling/core/custom_types.py
re
¶
Call the .re() method for each element in this list and return
their results flattened as TextHandlers.
| PARAMETER | DESCRIPTION |
|---|---|
regex
|
Can be either a compiled regular expression or a string.
TYPE:
|
replace_entities
|
If enabled character entity references are replaced by their corresponding character
TYPE:
|
clean_match
|
if enabled, this will ignore all whitespaces and consecutive spaces while matching
TYPE:
|
case_sensitive
|
if disabled, the function will set the regex to ignore the letters-case while compiling it
TYPE:
|
Source code in scrapling/core/custom_types.py
re_first
¶
Call the .re_first() method for each element in this list and return
the first result or the default value otherwise.
| PARAMETER | DESCRIPTION |
|---|---|
regex
|
Can be either a compiled regular expression or a string.
TYPE:
|
default
|
The default value to be returned if there is no match
TYPE:
|
replace_entities
|
If enabled character entity references are replaced by their corresponding character
TYPE:
|
clean_match
|
If enabled, this will ignore all whitespaces and consecutive spaces while matching
TYPE:
|
case_sensitive
|
If disabled, function will set the regex to ignore the letters-case while compiling it
TYPE:
|
Source code in scrapling/core/custom_types.py
get
¶
Returns the first item of the current list
| PARAMETER | DESCRIPTION |
|---|---|
default
|
the default value to return if the current list is empty
DEFAULT:
|
scrapling.core.custom_types.AttributesHandler
¶
Bases: Mapping[str, _TextHandlerType]
flowchart TD
scrapling.core.custom_types.AttributesHandler[AttributesHandler]
click scrapling.core.custom_types.AttributesHandler href "" "scrapling.core.custom_types.AttributesHandler"
A read-only mapping to use instead of the standard dictionary for the speed boost, but at the same time I use it to add more functionalities.
If the standard dictionary is needed, convert this class to a dictionary with the dict function
Source code in scrapling/core/custom_types.py
json_string
property
¶
Convert current attributes to JSON bytes if the attributes are JSON serializable otherwise throws error
get
¶
search_values
¶
Search current attributes by values and return a dictionary of each matching item
| PARAMETER | DESCRIPTION |
|---|---|
keyword
|
The keyword to search for in the attribute values
TYPE:
|
partial
|
If True, the function will search if keyword in each value instead of perfect match
TYPE:
|