Re:Requests-HTML: HTML Parsing for Humans
by Giroflex on Monday February 26, 2018 @11:03AM
(#16466242)
I actually had the same experience. I was scraping a large number of pages and upon profiling my script, I found out that bs4 was really slow. Changing the parser from the default to lxml helped things a bit, but I decided I would just try a regex to check quickly whether things could be better. Lo and behold, it was much faster. It's true that it's impossible to parse HTML in its entirety with regex, but if you're looking to extract only a portion of data from a page with a known structure, a bit of regex might be the way to go.
Re:Requests-HTML: HTML Parsing for Humans
by jcadam on Monday February 26, 2018 @08:08AM
(#16464977)
You're using regex to parse html? Have you not read: https://stackoverflow.com/a/1732454/1090568 ?
Re:Requests-HTML: HTML Parsing for Humans
by wodenokoto on Tuesday February 27, 2018 @04:04PM
(#16477864)
If you have an HTML document you want to extract information from, regexes are fast and easy.
It's when you don't have guarantees about the structure of the html you are working with, that regex will come up short.
Now, I very rarely have any need to scrape and parse html data, and I was scratching my head at how it was taking these parsers so long to parse a 3.5 mib html page. I mean, it should be able to go through that and get what I want in under a second right?
So, I said screw it and wrote some regexes. 10-15 seconds was how long it was now taking to parse that html. It actually took 1.5 or so seconds to parse the html; the rest was waiting for it to download the webpage.
Ironically, implementing the regexes was actually quicker than figuring out how to use those html parsers and write the code. Of course, that's assuming you know how to craft regexes. Since it was set-up to run every 5 minutes, I wanted something that could do it without spending 1/2 the time parsing the data(amongst other tasks the processors were needed for).
YMMV