MCPcopy
hub / github.com/psf/requests-html / next

Method next

requests_html.py:433–472  ·  view source on GitHub ↗

Attempts to find the next page, if there is one. If ``fetch`` is ``True`` (default), returns :class:`HTML ` object of next page. If ``fetch`` is ``False``, simply returns the next URL.

(self, fetch: bool = False, next_symbol: _NextSymbol = DEFAULT_NEXT_SYMBOL)

Source from the content-addressed store, hash-verified

431 return f"<HTML url={self.url!r}>"
432
433 def next(self, fetch: bool = False, next_symbol: _NextSymbol = DEFAULT_NEXT_SYMBOL) -> _Next:
434 """Attempts to find the next page, if there is one. If ``fetch``
435 is ``True`` (default), returns :class:`HTML <HTML>` object of
436 next page. If ``fetch`` is ``False``, simply returns the next URL.
437
438 """
439
440 def get_next():
441 candidates = self.find('a', containing=next_symbol)
442
443 for candidate in candidates:
444 if candidate.attrs.get('href'):
445 # Support 'next' rel (e.g. reddit).
446 if 'next' in candidate.attrs.get('rel', []):
447 return candidate.attrs['href']
448
449 # Support 'next' in classnames.
450 for _class in candidate.attrs.get('class', []):
451 if 'next' in _class:
452 return candidate.attrs['href']
453
454 if 'page' in candidate.attrs['href']:
455 return candidate.attrs['href']
456
457 try:
458 # Resort to the last candidate.
459 return candidates[-1].attrs['href']
460 except IndexError:
461 return None
462
463 __next = get_next()
464 if __next:
465 url = self._make_absolute(__next)
466 else:
467 return None
468
469 if fetch:
470 return self.session.get(url)
471 else:
472 return url
473
474 def __iter__(self):
475

Callers 3

__next__Method · 0.95
__anext__Method · 0.95
__iter__Method · 0.80

Calls 1

_make_absoluteMethod · 0.80

Tested by

no test coverage detected