News for hackers. Stuff that matters.
Re:PHP Simple HTML DOM Parser by encoderer on Friday December 11, 2009 @03:26PM (#990381)
I've been using this for some serious scraping recently... dozens of threads scraping for 5, 6 days at a time.

Very good application, but watch out for memory leaks. Leaks like a sieve when you miss a ->clear() call in your destructors if you're not using the circular reference detection feature in the 5.3 garbage collector.

Re:PHP Simple HTML DOM Parser by crux_ on Friday December 11, 2009 @05:34PM (#990671)
Since folks here seem to be in the know, if I were after "parsing as close to the browser as possible", ideally in Java/Scala or Ruby or Python (sorry PHP!) -- any recommendations?

I've done scraping (e.g. w/ BeautifulSoup) but haven't looked to see how true the parses are to what IE/FF/WebKit would produce.

(On my list of things to look into: html5lib -- http://code.google.com/p/html5lib/ ... is it any good?)

Re:PHP Simple HTML DOM Parser by fizx on Saturday December 12, 2009 @01:00AM (#991243)
Run headless Firefox+xvfb+Selenium. Selenium has java, ruby, and python clients. This is working really well in production.

You might also have luck with AppleScript/RubyCocoa/MacRuby+Safari. I've tried a couple other options like HTMLUnit (which google uses with GWT), and Mozilla Java Html Parser, which Dapper.net uses. I couldn't get them running, but YMMV.

Re:PHP Simple HTML DOM Parser by tremendo on Friday December 11, 2009 @09:30PM (#991024)
for Ruby there's Hpricot and Nokogiri. Now I must admit not understanding what "parsing as close to the browser as possible" would mean. These parsers would not be for displaying the HTML, they're not rendering engines like those in browsers, but will help you navigate the DOM of a (X)(HT)ML document programatically. Surely I'm missing your meaning.
Re:PHP Simple HTML DOM Parser by crux_ on Sunday December 13, 2009 @10:16AM (#992763)
What I'm aiming at would mean "given this lump of (malformed) HTML, what DOM would a browser give me?" Maybe Hpricot, BeautifulSoup, et al are already there, but I don't know. :)
Re:PHP Simple HTML DOM Parser by yannis on Friday December 11, 2009 @03:29PM (#990392)
Another way to get to the DOM, especially if you are using tidy to clean-up your HTML is tidy itself http://php.net/manual/en/book.tidy.php It is not very hard to get elements using tidy, but you need to write your own functions. However, is almost bullet-proof as it can correct for malformed HTML which some of the other libaries don't.
Re:PHP Simple HTML DOM Parser by dshah on Sunday December 13, 2009 @04:00PM (#993106)
I'm using Tidy now, and it's been working pretty well. What I do is use Tidy to convert mal-formed HTML to XHTML and then use the Simple XML methods for my parsing.

Anyone know if this new library is better than that approach?

Re:PHP Simple HTML DOM Parser by gorm on Friday December 11, 2009 @03:08PM (#990350)
http://code.google.com/p/phpquery/ This also seems interesting.
Re:PHP Simple HTML DOM Parser by danw on Friday December 11, 2009 @04:07PM (#990473)
I've used this before. It's got a lovely api but uses far too much memory.
Re:PHP Simple HTML DOM Parser by larrykubin on Friday December 11, 2009 @05:03PM (#990616)
For Python folks, check out pyquery (http://www.pyquery.org/). It's really handy.
Re:PHP Simple HTML DOM Parser by mildweed on Friday December 11, 2009 @02:54PM (#990321)
This is a good one to be sure. Also, check out QueryPath (http://querypath.org/).
Re:PHP Simple HTML DOM Parser by kylemathews on Friday December 11, 2009 @07:47PM (#990914)
I used QueryPath for a recent project and really liked it. Its selectors are almost identical to jQuery's so the learning curve was shallow. Two thing QueryPath does that this library doesn't seem to is work w/ XML and allow for chainable method calls. See this IBM Developer Work's article http://www.ibm.com/developerworks/opensource/library/os-php-...
Re:PHP Simple HTML DOM Parser by grumpycanuck on Friday December 11, 2009 @05:09PM (#990626)
As someone who works with XML all day long, I am wondering why people don't use SimpleXML in PHP 5+ for this sort of thing too.
Re:PHP Simple HTML DOM Parser by tetsuo13 on Friday December 11, 2009 @05:10PM (#990629)
SimpleXML will choke on invalid HTML/XML while this library claims to support it.
Re:PHP Simple HTML DOM Parser by vinhboy on Friday December 11, 2009 @09:50PM (#991048)
you guys read my mind.. i've been needing one of these.