MCPcopy
hub / github.com/scrapy/scrapy / _url_from_selector

Function _url_from_selector

scrapy/http/response/text.py:301–314  ·  view source on GitHub ↗
(sel: parsel.Selector)

Source from the content-addressed store, hash-verified

299
300
301def _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)

Callers 2

followMethod · 0.85
follow_allMethod · 0.85

Calls 2

_InvalidSelectorClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…