Add test to make sure spider doesn't crash on bad

This commit is contained in:
Samuel Bartlett 2023-03-31 08:07:43 +00:00
parent 9ef00c5c0b
commit 9cbcf7724d
1 changed files with 23 additions and 0 deletions

View File

@ -815,3 +815,26 @@ class LxmlLinkExtractorTestCase(Base.LinkExtractorTestCase):
def test_restrict_xpaths_with_html_entities(self):
super().test_restrict_xpaths_with_html_entities()
def test_skip_bad_links(self):
html = b"""
<a href="http://example.org/ignore_links : http://example.com/like_this">Why would you do this?</a>
<a href="http://example.org/item2.html">Good Link</a>
<a href="http://example.org/item3.html">Good Link 2</a>
"""
response = HtmlResponse("http://example.org/index.html", body=html)
self.assertEqual(
[link for link in lx.extract_links(response)],
[
Link(
url="http://example.org/item2.html",
text="Good Link",
nofollow=False,
),
Link(
url="http://example.org/item3.html",
text="Good Link 2",
nofollow=False,
),
],
)