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

Method base_url

requests_html.py:341–362  ·  view source on GitHub ↗

The base URL for the page. Supports the `` `` tag (`learn more `_).

(self)

Source from the content-addressed store, hash-verified

339
340 @property
341 def base_url(self) -> _URL:
342 """The base URL for the page. Supports the ``<base>`` tag
343 (`learn more <https://www.w3schools.com/tags/tag_base.asp>`_)."""
344
345 # Support for <base> tag.
346 base = self.find('base', first=True)
347 if base:
348 result = base.attrs.get('href', '').strip()
349 if result:
350 return result
351
352 # Parse the url to separate out the path
353 parsed = urlparse(self.url)._asdict()
354
355 # Remove any part of the path after the last '/'
356 parsed['path'] = '/'.join(parsed['path'].split('/')[:-1]) + '/'
357
358 # Reconstruct the url with the modified path
359 parsed = (v for v in parsed.values())
360 url = urlunparse(parsed)
361
362 return url
363
364
365class Element(BaseParser):

Callers

nothing calls this directly

Calls 1

findMethod · 0.95

Tested by

no test coverage detected