Fields
Bases: property
Shortcut for adding property-like descriptors in BaseSchema,
which will go into the output of the dict() method.
Works like build-in @property decorator
Source code in scrape_schema/base.py
__init__(auto_type=True, default=..., alias=None, **kwargs)
Base Field class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auto_type
|
bool
|
usage auto_type feature. default True. works in BaseSchema object |
True
|
default
|
Any
|
default value if parsing runtime will catch an error. Throws an error by default |
...
|
alias
|
Optional[str]
|
alias fields to display in the BaseSchema object. If no value is specified, will apply the key of the given attribute |
None
|
Source code in scrape_schema/base.py
Bases: BaseField
Source code in scrape_schema/base.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
success
property
last parsed field status
__getitem__(item)
This method provide getitem API (get by key or slice)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
Hashable
|
key or slice |
required |
__log_debug_markup_len(markup)
staticmethod
this method for logging module
Source code in scrape_schema/base.py
__log_debug_markup_part(markup, max_len=64)
staticmethod
this method for logging module
Source code in scrape_schema/base.py
add_method(method_name, *args, **kwargs)
low-level interface adding methods to call stack
capitalize()
Same as str.capitalize() method.
If last chain list[str] argument - invoke this method to all arguments
chomp_js_parse(unicode_escape=False, json_params=None)
Extracts first JSON object encountered in the input string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unicode_escape
|
Any
|
Attempt to fix input string if it contains escaped special characters |
False
|
json_params
|
Any
|
Allow passing down standard |
None
|
Returns:
| Type | Description |
|---|---|
SpecialMethodsProtocol
|
Extracted JSON object |
Source code in scrape_schema/base.py
chomp_js_parse_all(unicode_escape=False, omitempty=False, json_params=None)
Returns a list extracting all JSON objects encountered in the input string. Can be used to read JSON Lines
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unicode_escape
|
Any
|
Attempt to fix input string if it contains escaped special characters |
False
|
omitempty
|
Any
|
Skip empty dictionaries and lists |
False
|
json_params
|
Any
|
Allow passing down standard |
None
|
Returns:
| Type | Description |
|---|---|
SpecialMethodsProtocol
|
Iterating over it yields all encountered JSON objects |
Source code in scrape_schema/base.py
concat_l(left_string)
add string to left. Last argument should be string value + left_string Args: left_string:
Returns:
| Type | Description |
|---|---|
SpecialMethodsProtocol
|
concatenated value |
Source code in scrape_schema/base.py
concat_r(right_string)
add string to right. Last argument should be string right_string + value Args: right_string:
Returns:
| Type | Description |
|---|---|
SpecialMethodsProtocol
|
concatenated string |
Source code in scrape_schema/base.py
count()
Return items count.
if last chain value is list - return len value else 1
fn(function)
call another function and return result
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
Callable[..., Any]
|
function to be executed |
required |
Returns:
| Type | Description |
|---|---|
SpecialMethodsProtocol
|
executed function result |
Source code in scrape_schema/base.py
join(join_sep)
Same as str.join() method.
If last chain list[str] argument - raise TypeError
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
join_sep
|
str
|
separate char for result |
required |
Source code in scrape_schema/base.py
lower()
Same as str.lower() method.
If last chain list[str] argument - invoke this method to all arguments
lstrip(chars=None)
Same as str.lstrip() method.
If last chain list[str] argument - invoke this method to all arguments
Args:
chars: strip chars. Default strip left whitespaces ( ,
included)
Source code in scrape_schema/base.py
re_findall(pattern, flags=0, groupdict=False)
[match for match in re.finditer(...)] method for text result.
Last chain should be return string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
Union[str, Pattern[str]]
|
regex pattern |
required |
flags
|
Union[int, RegexFlag]
|
regex compilation flags |
0
|
groupdict
|
bool
|
accept groupdict method. patter required named groups. default False |
False
|
Raises:
| Type | Description |
|---|---|
AttributeError
|
if groupdict=True and pattern not contains named groups |
Source code in scrape_schema/base.py
re_search(pattern, flags=0, groupdict=False)
re.search method for text result.
Last chain should be return string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
Union[str, Pattern[str]]
|
regex pattern |
required |
flags
|
Union[int, RegexFlag]
|
regex compilation flags |
0
|
groupdict
|
bool
|
accept groupdict method. pattern required named groups. default False |
False
|
Raises: AttributeError: if groupdict=True and pattern not contains named groups
Source code in scrape_schema/base.py
replace(old, new, count=-1)
str.replace method. Last argument should be string. old string replaced by new
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old
|
str
|
string |
required |
new
|
str
|
string |
required |
count
|
int
|
Maximum number of occurrences to replace. -1 (default) means replace all occurrences. |
-1
|
Returns:
| Type | Description |
|---|---|
SpecialMethodsProtocol
|
replaced string |
Source code in scrape_schema/base.py
rstrip(chars=None)
Same as str.rstrip() method.
If last chain list[str] argument - invoke this method to all arguments
Args:
chars: strip chars. Default strip right whitespaces ( ,
included)
Source code in scrape_schema/base.py
sc_parse(markup)
parse field entrypoint. Execute all passed methods
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markup
|
Union[str, bytes, Selector, SelectorList]
|
markup target |
required |
Returns:
| Type | Description |
|---|---|
Any
|
result of all executed methods |
Source code in scrape_schema/base.py
split(sep=None, max_split=-1)
Same as str.split() method.
If last chain list[str] argument - raise TypeError
Source code in scrape_schema/base.py
strip(chars=None)
Same as str.strip() method.
If last chain list[str] argument - invoke this method to all arguments
Args:
chars: strip chars. Default strip all whitespaces ( ,
included)
Source code in scrape_schema/base.py
upper()
Same as str.upper() method.
If last chain list[str] argument - invoke this method to all arguments
Bases: Field
This field provide parsel.Selector api and special methods
Source code in scrape_schema/field.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
attrib
property
Return the attributes dictionary for the first element.
If the list is empty, return an empty dict.
Returns:
| Type | Description |
|---|---|
AttribProtocol
|
dict[str, str] |
raw_text
property
Shortcut Parsel().xpath('//p/text()') call.
This method for getting raw text (not html), when calling parsel.Selector
methods will raise an error
__init__(auto_type=True, default=..., *, raw=False, alias=None)
Base field provide Parsel.Selector API and special methods
Args:
auto_type: usage auto type feature in BaseSchema scope. Default True
default: set default value, if method return traceback.
Disable auto type andIf not set - raise error
raw: raw text parse mode. Auto accept .xpath("//p/text()").get() method
alias: field alias. default None
Source code in scrape_schema/field.py
css(query)
Apply the given CSS selector and return a SelectorList instance.
query is a string containing the CSS selector to apply.
In the background, CSS queries are translated into XPath queries using cssselect library and run .xpath() method.
Source code in scrape_schema/field.py
get(default=None, key=None)
Serialize and return the matched nodes in a single string.
Percent encoded content is unquoted.
If key param passed - get value from attrib property.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default
|
Optional[str]
|
invoke Selector.get() method and return default value if is None |
None
|
key
|
Optional[Hashable]
|
get value from attrib property attrib should be called in chain methods |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if passed default and key arguments |
Source code in scrape_schema/field.py
getall()
Call the .get() method for each element is this list and return their results flattened, as a list of strings.
Returns:
| Type | Description |
|---|---|
SpecialMethodsProtocol
|
list[str] |
items()
Get attrib items
Returns:
| Type | Description |
|---|---|
SpecialMethodsProtocol
|
dict items |
Raises: TypeError: if prev chain is not attrib
jmespath(query, **kwargs)
Find objects matching the JMESPath query and return the result as a
SelectorList instance with all elements flattened.
List elements implement Selector interface too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
JMESPath string query |
required |
**kwargs
|
Any
|
Any additional named arguments are passed to the underlying |
{}
|
Source code in scrape_schema/field.py
keys()
Get attrib keys
Returns:
| Type | Description |
|---|---|
SpecialMethodsProtocol
|
dict keys |
Raises: TypeError: if prev chain is not attrib
re(regex, replace_entities=True)
Apply the given regex and return a list of strings with the matches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regex
|
Union[str, Pattern[str]]
|
regular expression |
required |
replace_entities
|
bool
|
replace char entity refers replaced by their corresponding char ( |
True
|
Returns:
| Type | Description |
|---|---|
SpecialMethodsProtocol
|
string |
Source code in scrape_schema/field.py
values()
Get attrib values
Returns:
| Type | Description |
|---|---|
SpecialMethodsProtocol
|
dict_values |
Raises: TypeError: if prev chain is not attrib
xpath(query, namespaces=None, **kwargs)
Xpath selector
Args:
query: is a string containing the XPATH query to apply.
namespaces: is an optional prefix: namespace-uri mapping (dict) for additional prefixes.
**kwargs: field alias. default None
Returns:
| Type | Description |
|---|---|
Self
|
SelectorList |
Source code in scrape_schema/field.py
Bases: Field
This field provide parsel.Selector api and special methods for json data
Source code in scrape_schema/field.py
__init__(auto_type=False, default=..., alias=None)
this field provide jmespath and special methods API
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auto_type
|
bool
|
usage auto_type feature. Default False |
False
|
default
|
Any
|
default |
...
|
alias
|
Optional[str]
|
field alias. default None |
None
|
Source code in scrape_schema/field.py
get(default=None)
Serialize and return the matched nodes in a single string.
Percent encoded content is unquoted.
If key param passed - get value from attrib property.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default
|
Optional[str]
|
invoke Selector.get() method and return default value if is None |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
if passed default and key arguments |
Source code in scrape_schema/field.py
getall()
Call the .get() method for each element is this list and return their results flattened, as a list of strings.
Returns:
| Type | Description |
|---|---|
SpecialMethodsProtocol
|
list[str] |
Source code in scrape_schema/field.py
jmespath(query, **kwargs)
Find objects matching the JMESPath query and return the result as a
SelectorList instance with all elements flattened.
List elements implement Selector interface too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
JMESPath string query |
required |
**kwargs
|
Any
|
Any additional named arguments are passed to the underlying |
{}
|
Source code in scrape_schema/field.py
Bases: Field
This field provide special methods for raw text data (regex only)
Source code in scrape_schema/field.py
__init__(auto_type=True, default=..., alias=None)
this field provide special methods API
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auto_type
|
bool
|
usage auto type feature in BaseSchema scope. Default True |
True
|
default
|
Any
|
set default value, if method return traceback. |
...
|
alias
|
Optional[str]
|
field alias. default None |
None
|