Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Parsing HTML

Name: Anonymous 2011-07-23 20:48

You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML. As I have answered in HTML-and-regex questions here so many times before, the use of regex will not allow you to consume HTML. Regular expressions are a tool that is insufficiently sophisticated to understand the constructs employed by HTML. HTML is not a regular language and hence cannot be parsed by regular expressions. Regex queries are not equipped to break down HTML into its meaningful parts. so many times but it is not getting to me. Even enhanced irregular regular expressions as used by Perl are not up to the task of parsing HTML. You will never make me crack. HTML is a language of sufficient complexity that it cannot be parsed by regular expressions. Even Jon Skeet cannot parse HTML using regular expressions. Every time you attempt to parse HTML with regular expressions, the unholy child weeps the blood of virgins, and Russian hackers pwn your webapp. Parsing HTML with regex summons tainted souls into the realm of the living. HTML and regex go together like love, marriage, and ritual infanticide. The <center> cannot hold it is too late. The force of regex and HTML together in the same conceptual space will destroy your mind like so much watery putty. If you parse HTML with regex you are giving in to Them and their blasphemous ways which doom us all to inhuman toil for the One whose Name cannot be expressed in the Basic Multilingual Plane, he comes. HTML-plus-regexp will liquify the n​erves of the sentient whilst you observe, your psyche withering in the onslaught of horror. Rege̿̔̉x-based HTML parsers are the cancer that is killing /prog/ it is too late it is too late we cannot be saved the trangession of a chi͡ld ensures regex will consume all living tissue (except for HTML which it cannot, as previously prophesied) dear lord help us how can anyone survive this scourge using regex to parse HTML has doomed humanity to an eternity of dread torture and security holes using regex as a tool to process HTML establishes a breach between this world and the dread realm of c͒ͪo͛ͫrrupt entities (like SGML entities, but more corrupt) a mere glimpse of the world of reg​ex parsers for HTML will ins​tantly transport a programmer's consciousness into a world of ceaseless screaming, he comes, the pestilent slithy regex-infection wil​l devour your HT​ML parser, application and existence for all time like Visual Basic only worse he comes he comes do not fi​ght he com̡e̶s, ̕h̵i​s un̨ho͞ly radiańcé destro҉ying all enli̍̈́̂̈́ghtenment, HTML tags lea͠ki̧n͘g fr̶ǫm ̡yo​͟ur eye͢s̸ ̛l̕ik͏e liquid pain, the song of re̸gular exp​ression parsing will exti​nguish the voices of mor​tal man from the sp​here I can see it can you see ̲͚̖͔̙î̩́t̲͎̩̱͔́̋̀ it is beautiful t​he final snuffing of the lie​s of Man ALL IS LOŚ͖̩͇̗̪̏̈́T ALL I​S LOST the pon̷y he comes he c̶̮omes he comes the ich​or permeates all MY FACE MY FACE ᵒh god no NO NOO̼O​O NΘ stop the an​*̶͑̾̾​̅ͫ͏̙̤g͇̫͛͆̾ͫ̑͆l͖͉̗̩̳̟̍ͫͥͨe̠̅s ͎a̧͈͖r̽̾̈́͒͑e n​ot rè̑ͧ̌aͨl̘̝̙̃ͤ͂̾̆ ZA̡͊͠͝LGΌ ISͮ̂҉̯͈͕̹̘̱ TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ

So how should I go about parsing HTML?

Name: Anonymous 2011-07-23 21:04

Actually, you can. Being that Universe is finite, you can construct a regexp, that will match any imaginable pattern in the whole universe.

Name: Anonymous 2011-07-23 21:07

>>2
This is wrong

Name: Anonymous 2011-07-23 21:08

>>3
You're wrong.

Name: Anonymous 2011-07-23 21:13

Never mind. I used a regex. Worked flawlessly.

Name: Anonymous 2011-07-23 21:34

>>1
You have made an excellent post. I admire you.

Name: Anonymous 2011-07-23 21:36

I used regex once on a spider I built once. The problem is that much [X]HTML that you encounter will not be truly valid (people really suck at writing HTML it seems.)

That being said, occasionally some HTML will break your regex, and something will slip by that shouldn't. This isn't a problem if you're parsing a small set of files that you believe to be valid; however, you can imagine it would be problematic for a spider that tries to scrape links from everything.

Name: Anonymous 2011-07-23 21:38

>>7 here
Maybe use small regexs that search for starting tags, then the ending tag for the same starting tag, and use recursion to create a queryable tree structure.

Name: Anonymous 2011-07-23 21:43

>>7
Use bigger regexp. Try enumerating all cases.

Name: XML::Parser 2011-07-23 21:44

XML::Parser

Name: XML::Parser 2011-07-23 21:44

XML::Parser

Name: Anonymous 2011-07-23 21:47

xml no good with regex. xml parser makes happy me. i use xml pareser all time

Name: Anonymous 2011-07-23 21:47

xml no good with regex. xml parser makes happy me. i use xml pareser all time

Name: Anonymous 2011-07-23 23:03

>>1
the One whose Name cannot be expressed in the Basic Multilingual Plane
I love you.

Name: Anonymous 2011-07-24 2:18

Is is possible to match nested constructs with regex (Without Perl 6's magical regex)?

Name: Anonymous 2011-07-24 3:00

Go back to StackOverflow.

Name: Anonymous 2011-07-24 3:52

>>16
You didn't say please.

Name: Anonymous 2012-03-05 18:49

Name: Anonymous 2012-03-05 19:44

Name: Anonymous 2012-03-05 23:32

>>15 it wouldn't be regular, but there are such magical regexes that do. Lua has a balanced brace matching expression. No actual regular expressions though.

Name: Anonymous 2012-03-06 3:48

this post is pure gold!

Name: Anonymous 2012-03-06 4:03

Name: Anonymous 2012-03-06 8:46

Name: Anonymous 2012-03-06 16:33

write your own fucking program to do what you want. You are a programmer are you not. If not get off of /prog/ I am tired of these racist script kiddie leets.

Name: Anonymous 2013-08-17 9:30

BeautifulSoup4

Name: Anonymous 2013-08-17 9:32

̵͍̜͔͙̗̼͚̫̒͊ͯ̇͌̃̈́͟͞r̢ͤ̉̄ͣ͋͏͓́e̷̢͕̠ͮ̈́̆ͅp̡̯̮̲͇͕̩ͧ̇̍̚̕ŗ͇͖̒̎͋ͪͣe̸̴̢͎̖̠̫̪͔̽́̽͛ͅs̹̳͖͉͇̣̻̊ͣͤ̄̌͛̓̚͟e͐ͪ̋̿̓͏̠͚̼̪̣̰ͅn̶͖̖͕̺̠͔̻͈̐ͬͫͫ̑͘t̥̪̤̹͎̹̞ͧ͑ͧ͝͡ͅị̮̩̥̮͙͎̓͑͠ͅn̷̼͔̗͎̩̫͔͊g̶̞̱̝͙̝͙̋́̄͌̅͢͝ ̘͙̮ͫ̉ͪ͢c̟̲͕͕̩̓̎͞ḣ̶̸̩͚̦̬̱̤͔̹͈́̔͐ͤ͡aͭ̃̐̌ͮͦ͏̫̜̣̬̲̙̭͢ò̠̭̖ͥͩ̈́͆̓̈s̴̛͓͓̲̲͋̊͑̐̓ͩͬ͑.͎̳̄͋ ̷̢̹̳͙̹̙͍̙̅̂ͩͧ̾̚I̮̤̪̹̠̾͋̃n̶̺̫͓̲̥̠͔̄́̓ͪ̍͋͢v̡̭͕͙̣ͫ̎ͮ͐̄̇͛̚̕ͅoͬͧ̿ͫ̔̉ͫ̽̚҉͈̦͕k̸̽̎̐͏̱͇͜ḯ҉̵̻̣̫̞̭̳̰͖̬n̷̜͖̞̮̬͈͖͍̿̓͂͛̾͋̽̉͠͝g̡̰̹͌ͨ̆ͬͯ͌ͥ̋̚͡ ̴̨͙̲̪̜ͤͥͤ̉ͫͯ̒̉ẗ̨̬̹̼̯͆̍ͮ̓͘hͬ̽҉̛͓̘̩̯̥̜e͂̏̓̿̍͠҉̣̲̳̮̩͍̕ ͕̼͇̙̪̣̠͈͔ͭͯ̀ͭ͒f͎̗̳͎̥̈́̑͌͛̌̏ͥ͞e̸̡̠͉͓̰̙ͣͭ̈͊̈̐̔̊ḛ̦͕̯̋̒ͭ̇̅̿͡l̶̝͓̳̗̮̻͍̯̋ͨ̅̊̅̾ĭ͕̬̥̥̾ͣ̓n̶̝̞̬̦̄̃g̥̖͇͙̠̽ͬ́ͯ̽ͫ̉ ̳͈̪́͛ͯͫ́ͬͯ̑o͔̰̪̰͒̎ͮ͘͢f͖͓͇̣ͨ͂ͤ̚̕ ̛̘͍̗̣̟̬̼ͥ̓c̵̸͔̩͔̩̫̰̜̐͑̎ͯ̚ͅh̨͙͈̥̉ͫ̈̿͆̔ͣä̧̺̪͔͔̱͓̠̞ͮ̇͒̍̊o̶̴̟̱̻̻͙͂͜s̼̱̣̩̦̺̖͕̈̆͋̒͂ͨͥ̀͞͝.͓̣͎̳͇̤͇̺͗ͩ͆̆̅ͤ͡͝ ̶̬̬̱̟̜̼̓̆͂̽̍ͣ̒͒͢͜Ẅ̧̦́ͩ̚iͫ͒͐͛̿͏̳͕̞̙͝t̺̝̣̥̻͓͂̐̏̍͢h̐́ͨ́͏̶̱̝̮̞͖͓̬ ̶̺͉̓͌̆ͯ̐̍ͤo͓̺̻̪̗̗̓̇ͭ͆ͪ̓̚̕͟ͅͅụ̧̡̠̰̭̒̅̄̒̊ͮ̈́t̞̯͓̲͕̗̹̤ͥ̋ͣ͌ ͖̐̌̑̉͑̉͟o̖̣̖͕ͤ̐͗̍͐͠r̬̃ͧ͌̈̔d̖͔̝̱͎̙͒ͫeͮ̌̔ͪ҉̣̠̰̳r̲̠̠̪̯̙̬̲ͬ̾ͪͪ̅ͥ̚͘.̵̝̜̣̝̙͚ͪ̑̃͆̂͘ ͍̪̼̦̲̰̇͑̋ͥ̓̍͒ͣͦ̕ͅT̴͙͙̱͚̳͕̤̩̈́̏̂ͩ̐ͅh̵̴͔̙̻̺͕̽e̙̗̜̞̓͑ͬ̓ͥͯͧ̂ ̴̲̲ͤͣ̀N͚͍̻̿̒͌̍͆e͕̹͖̊̔̏ͫ̍ͬͥ̚͠z̸̖̦̯̮̠̑p͎̭͂ͦ̇ͬͦ͌͞ḙ͆̆̉̽̉͗r̢̬͔̬͓̺͇͎̬̘̆ͤ́̆̋̕͝dͥͫ̊̾͋ͪͩ̒̐҉̙͇̩͉i͍̙̬̦͙͉͍ͮ͡ͅǎ̸̡̘̩̟̮̫̋̿̇̈́̀n̸̶̜̻̲̝̰̗͙̍̌̓͐̾ͯ̀ ̩̣̻͍͔̩̥̱̈̊̆̎̔̔͑̕h̵̸̝̳̮̫̙̮͖̬̔̂͗̂͞i̴̪͎̖̠͐́̋͌͜͞v̺́̔ͬͨ̉ͅë̬̙̪̞́̈́͐͋̃̒ͩ-̶̳̮̖̳͎̻͓̯̪ͬ̋̄ṃ̡̗̩̩̦ͨͧ͑̽̄͠i͈̭͖̞̫͔͋͑̆̆ͣ͜n͙̠̙̦̫̺̩̐͊̓̐̍̚d̷͓̜͖̪̼͉̟̤͛͑͗̋ ͉ͤͧͦ̄̓̔ͧ̍͑̕͘o̗̦̹̫̹ͭͤf̶̛̖̣̦̯͚̪̞̞ͨ̂̌̃̇̎̐ ̈̐̄̔̾͑͏̵͇̤̰c̠̘̗̹̰̬̱̝̖ͦ̒ͧ̿̌̿͘ḧ̫̙̬͇̳͍͔́̊͒ͮ́͂͡a̫̪͙͎͉̲͎̹͋͆ͮͪ̿ͪ͋o͇͉̒̊ͧ̃̋̈́̈́̀̕s̷͉̘̹̟̺̦̅͌.̵̮̝̠̎̈́̕͞ ̬̹̠͈̫͔͕̓ͭͮ̀̆ͪͅZ̩̻͎͓̯̲̓ͥͫͪ̎ą̹͔̖̖̱͍̥̞́̂̀̈ͭ͂̈̂͛l̨̮ͪ̒͌ͦ̊ͧ̊͛͘͜g̪͔̩̑͆̆̏͛͌ͩ̋ớ̢̳̮̫̬̣͈͔ͨ̽ͧ̔̋.͍̦͇͔̲͓͔̜ͯ͂̆̋́̕ ̡̯͈̺̣̮̙̒͒̀̆ -̷̡͖͖̫̩͎̙͙̖̖̕͟ͅ.̴̶̨̢̭̞̰̯̖̳͍͈̕-̶̨͔͕͓̯̭͕͢,̴̶̳̬͚͔̗̝̗̬-̱͇̬͖̝̩̘̣͓͈̮͜͞͡

Name: Anonymous 2013-08-17 11:01

FSA's cannot perform the recursion necessary to parse nested tags I know because I'm an EXPERT.

Name: Anonymous 2013-08-17 12:59


Don't change these.
Name: Email:
Entire Thread Thread List