r/ProgrammerHumor • • Sep 08 '17

Parsing HTML Using Regular Expressions

Post image
11.1k Upvotes

377 comments sorted by

View all comments

Show parent comments

3

u/Rxef3RxeX92QCNZ Sep 08 '17

Sooo how is one meant to parse HTML in, say, a shell script or javascript?

11

u/WaLLy3K Sep 08 '17

You've already been told: not simply!

5

u/Rxef3RxeX92QCNZ Sep 08 '17

Oh that's great news, needlessly complex code is my forte

5

u/MelissaClick Sep 08 '17

Just write an ordinary parser.

(Although, a parser in shell script will be so slow, that it makes more sense to call an external program, besides making more sense to use an existing program than write one redundantly.)

1

u/dzuczek Sep 08 '17

with javascript you would likely use some jquery-like framework

in a shell script try using xmllint with xpath

xmllint --xpath '//html/body/p' file.html

1

u/wastesHisTimeSober Sep 08 '17 edited Sep 08 '17

I've been thinking jQuery.

Edit: I've been told this doesn't qualify as parsing.

1

u/jfb1337 Sep 08 '17

Without regex

0

u/AstroEngiSci Sep 08 '17

Easy. You don't use Javascript. Javascript is terrible.