Need help with html parsing in python3, not well formed for xml.etree.ElementTree

I lose inappropriate tags all the time. I'm not sure why, this is the text on the Craigslist main page that looks good to me, but I didn’t completely clear it. Is there anything more forgiveness I could use, or is this the best option for parsing html with a standard library?

+3
source share
3 answers

Errors with inconsistent tags are most likely caused by inconsistent tags. Browsers are famous for accepting sloppy html, and have made it easier for web coders to write poorly-formed html, so there are a lot of them. There is no reason to believe that creagslist should be protected from poor web page designers.

You need to use a grammar that allows for these inconsistencies. If the parser you are using does not allow you to correctly determine the grammar, you are stuck. (There might be a better Python library for this, but I don't know that).

One option is to launch a web page using a tool such as Tidy, which clears such inconsistencies and then launches your parser.

+4
source

HTML BeautifulSoup. :

. . , , HTML .

.

Python 3 , .

+1

HTML , , , . HTML, , - BeautifulSup lxml.

lxml Python 3, HTML HTML. , c- . .

BeautifulSoup 3.1 supports Python 3, but is also considered a bad experiment, "and you are told not to use it, so in practice BeautifulSoup does not support Python 3, leaving lxml as the only alternative.

0
source

Source: https://habr.com/ru/post/1791805/


All Articles