MCPcopy
hub / github.com/scrapy/scrapy / test_follow_selector

Method test_follow_selector

tests/test_http_response_text.py:301–334  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

299 assert joined == absolute
300
301 def test_follow_selector(self):
302 resp = self._links_response()
303 urls = [
304 "http://example.com/sample2.html",
305 "http://example.com/sample3.html",
306 "http://example.com/sample3.html",
307 "http://example.com/sample3.html",
308 "http://example.com/sample3.html#foo",
309 "http://www.google.com/something",
310 "http://example.com/innertag.html",
311 ]
312
313 # select <a> elements
314 for sellist in [resp.css("a"), resp.xpath("//a")]:
315 for sel, url in zip(sellist, urls, strict=False):
316 self._assert_followed_url(sel, url, response=resp)
317
318 # select <link> elements
319 self._assert_followed_url(
320 Selector(text='<link href="foo"></link>').css("link")[0],
321 "http://example.com/foo",
322 response=resp,
323 )
324
325 # href attributes should work
326 for sellist in [resp.css("a::attr(href)"), resp.xpath("//a/@href")]:
327 for sel, url in zip(sellist, urls, strict=False):
328 self._assert_followed_url(sel, url, response=resp)
329
330 # non-a elements are not supported
331 with pytest.raises(
332 ValueError, match="Only <a> and <link> elements are supported"
333 ):
334 resp.follow(resp.css("div")[0])
335
336 def test_follow_selector_list(self):
337 resp = self._links_response()

Callers

nothing calls this directly

Calls 6

SelectorClass · 0.90
_links_responseMethod · 0.80
_assert_followed_urlMethod · 0.80
cssMethod · 0.45
xpathMethod · 0.45
followMethod · 0.45

Tested by

no test coverage detected