The base URL for the page. Supports the `` `` tag (`learn more `_).
(self)
| 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 | |
| 365 | class Element(BaseParser): |