(sel: parsel.Selector)
| 299 | |
| 300 | |
| 301 | def _url_from_selector(sel: parsel.Selector) -> str: |
| 302 | if isinstance(sel.root, str): |
| 303 | # e.g. ::attr(href) result |
| 304 | return strip_html5_whitespace(sel.root) |
| 305 | if not hasattr(sel.root, "tag"): |
| 306 | raise _InvalidSelector(f"Unsupported selector: {sel}") |
| 307 | if sel.root.tag not in {"a", "link"}: |
| 308 | raise _InvalidSelector( |
| 309 | f"Only <a> and <link> elements are supported; got <{sel.root.tag}>" |
| 310 | ) |
| 311 | href = sel.root.get("href") |
| 312 | if href is None: |
| 313 | raise _InvalidSelector(f"<{sel.root.tag}> element has no href attribute: {sel}") |
| 314 | return strip_html5_whitespace(href) |
no test coverage detected
searching dependent graphs…