Re:Parsing HTML Using Regular Expressions
by bryanrasmussen on Saturday July 01, 2017 @05:46PM
(#14679217)
you know when you first read that you think - damn straight you can't parse html with regex, but as it goes on the idea gets strangely enticing. I mean maybe, with the correct rituals, and a gun and a willingness to fight with ancient evils you could maybe parse some html with regex. A sort of Lovecraft/Action flick.
[ Parent
| on HN ]
Using regex in python to scrape some data from a website works just fine for me... shrugs
Re:Parsing HTML Using Regular Expressions
by Analemma_ on Saturday July 01, 2017 @07:02PM
(#14679583)
It’s an acceptable choice for scraping, because with scraping you usually go into it with the expectation that it will break and need updates sometimes as the scraped site changes. The warning bells are more for things like validating user input on your own site, where there might be security implications of an impossible parsing task.
Re:Parsing HTML Using Regular Expressions
by DonHopkins on Saturday July 01, 2017 @07:18PM
(#14679661)
And I use a handgun to hunt houseflies in my motel room after a week long crystal meth binge. Works just fine for me.
Re:Parsing HTML Using Regular Expressions
by scarface74 on Sunday July 02, 2017 @02:16PM
(#14683657)
Is there ever a good reason to use regex to do a web scraper instead of using a proper prebuilt parser and walking the DOM?
Re:Parsing HTML Using Regular Expressions
by bryanrasmussen on Sunday July 02, 2017 @06:09PM
(#14684607)
regex is your hammer and you just by chance happen to have a really nail shaped task to do?
Performance, perhaps?
Re:Parsing HTML Using Regular Expressions
by monk_e_boy on Saturday July 01, 2017 @07:00PM
(#14679572)
beautiful soup is a better tool.
Regex is fine for grabbing something in a page that you have looked at yourself.
Parsing millions of pages you don't have this option, you need something robust, a tool that is flexible, that doesn't barf out too many errors, that is quick.
Re:Parsing HTML Using Regular Expressions
by mackerson on Saturday July 01, 2017 @07:37PM
(#14679750)
BS4, requests and dataset are my go-to tools for simple scraping. Back when Bethesda pulled the paid mod nonsense on the Steam store I wrote a simple scraper to track and digest the changes people were making to their Skyrim reviews so I could tease out who was most offended, core fans with a lot of hours logged on the game or people who were just piling on the outrage bandwagon. I should dig back into that data some time.
Anyway, got the whole thing done in about 200 lines. Not bad to scrape 50,000 pages. Fun times.