There are plenty of good, real html parsers, so there's no need to try regex. Xpath is nice for scraping HTML, though it always turns out the stuff you need is in the middle of a bunch of other text.
Parsing HTML with Regex
11–20 of 34 posts
Re: Parsing HTML with Regex
#12I reckon that technically regex is a tool that can be used to parse HTML. It's just that you could only use it in a very trivial way that would be better suited to other tools.
Re: Parsing HTML with Regex
#13There are plenty of good, real html parsers, so there's no need to try regex. Xpath is nice for scraping HTML, though it always turns out the stuff you need is in the middle of a bunch of other text.
I would imagine that valid HTML could be parsed as XML, e.g. with the Python ElementTree XML API
Re: Parsing HTML with Regex
#14I had one class where we had to build a multi threaded search engine in java and parsing HTML with regex was a requirement. Regex was the downfall of about 50% of the class and the majority of the students who did well still had slight issues with their HTML parsing. Moral of the story is that regex is a poor solution for HTML. Not to mention, hours debugging regex is one of the least meaningful or rewarding experien…
Re: Parsing HTML with Regex
#15While I agree with the answer. What most people take from it is don't use Regex to scrape data from HTML. Which isn't exactly the point of it. Parsing HTML and scraping are two different things. If you know the exact HTML you are working with, using regex to extract the data is in my opinion a superior way of doing it. Less lines and generally less complexity. (Such as taking the name and id of an amazon product from…
Re: Parsing HTML with Regex
#16I had one class where we had to build a multi threaded search engine in java and parsing HTML with regex was a requirement. Regex was the downfall of about 50% of the class and the majority of the students who did well still had slight issues with their HTML parsing. Moral of the story is that regex is a poor solution for HTML. Not to mention, hours debugging regex is one of the least meaningful or rewarding experien…
Re: Parsing HTML with Regex
#17I reckon that technically regex is a tool that can be used to parse HTML. It's just that you could only use it in a very trivial way that would be better suited to other tools.
Ruby regular expressions have a \g operator which lets you call a sub expression - so technically they could be used to parse HTML if you're a masochist.
Re: Parsing HTML with Regex
#18While I agree with the answer. What most people take from it is don't use Regex to scrape data from HTML. Which isn't exactly the point of it. Parsing HTML and scraping are two different things. If you know the exact HTML you are working with, using regex to extract the data is in my opinion a superior way of doing it. Less lines and generally less complexity. (Such as taking the name and id of an amazon product from…
With today's widely available DOM manipulation tools (jsdom, phantom, zombie) and proper HTML parsers in javascript there is absolutely no reason to use RegExps.
Well, for starters, if you're not using Javascript. All four tools you mentioned are Javascript-based.
Re: Parsing HTML with Regex
#19I had one class where we had to build a multi threaded search engine in java and parsing HTML with regex was a requirement. Regex was the downfall of about 50% of the class and the majority of the students who did well still had slight issues with their HTML parsing. Moral of the story is that regex is a poor solution for HTML. Not to mention, hours debugging regex is one of the least meaningful or rewarding experien…
I'd like to hire the minority students, since it seems that they quite literally accomplished the impossible!
Re: Parsing HTML with Regex
#20English, as any other natural language, is (at least mostly) a context free language too, but you wouldn't go around telling people that you shouldn't ever use regexen to match certain constructions in English text, right?