Parcourir la source

Correctly handle HTML with no <body> tags.

tags/v0.2
Ben Kurtovic il y a 10 ans
Parent
révision
3dde1c5d60
1 fichiers modifiés avec 4 ajouts et 0 suppressions
  1. +4
    -0
      earwigbot/wiki/copyvios/parsers.py

+ 4
- 0
earwigbot/wiki/copyvios/parsers.py Voir le fichier

@@ -136,6 +136,10 @@ class HTMLTextParser(BaseTextParser):
except ValueError:
soup = bs4.BeautifulSoup(self.text).body

if not soup:
# No <body> tag present in HTML ->
# no scrapable content (possibly JS or <frame> magic):
return ""
is_comment = lambda text: isinstance(text, bs4.element.Comment)
for comment in soup.find_all(text=is_comment):
comment.extract()


Chargement…
Annuler
Enregistrer