Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Scraping in Php [duplicate]

I've been doing some HTML scraping in PHP using regular expressions. This works, but the result is finicky and fragile. Has anyone used any packages that provide a more robust solution? A config driven solution would be ideal, but I'm not picky.

like image 563
tsellon Avatar asked Aug 29 '08 07:08

tsellon


2 Answers

I would recomend PHP Simple HTML DOM Parser after you have scraped the HTML from the page. It supports invalid HTML, and provides a very easy way to handle HTML elements.

like image 104
Espo Avatar answered Sep 18 '22 11:09

Espo


If the page you're scraping is valid X(HT)ML, then any of PHP's built-in XML parsers will do.

I haven't had much success with PHP libraries for scraping. If you're adventurous though, you can try simplehtmldom. I'd recommend Hpricot for Ruby or Beautiful Soup for Python, which are both excellent parsers for HTML.

like image 26
John Douthat Avatar answered Sep 21 '22 11:09

John Douthat