|  | parsing html with php5 |  | |
| | | juicymixx |  |
| Posted: Wed Aug 27, 2008 9:04 pm Post subject: parsing html with php5 |  |
I must be completely missing something here. I can't seem to figure out how to parse using the DOM in PHP5... For instance, as a test I'm trying to scrape out the weather conditions table from: LINK
I've tried several options, but am currently working on: $url = 'http://www.ufl.edu/weather'; $dom = new DOMDocument(); $doc->validateOnParse = true; $dom->loadHTML($url); $xpath = new DOMXPath($dom); $result = $xpath->query("/html/body/div[@id='mainContainer']/div/ table");
What am I missing here? If I query anything past '/html/body' I end up with no result...? |
| |
| | | Hans-Werner Hilse |  |
| Posted: Thu Aug 28, 2008 3:35 pm Post subject: Re: parsing html with php5 |  |
Hi,
juicymixx <juicymixx@gmail.com> wrote:
| Quote: | I've tried several options, but am currently working on: $url = 'http://www.ufl.edu/weather'; $dom = new DOMDocument(); $doc->validateOnParse = true; $dom->loadHTML($url);
|
that line should be $dom->loadHTMLFile($url);
| Quote: | $xpath = new DOMXPath($dom); $result = $xpath->query("/html/body/div[@id='mainContainer']/div/ table");
What am I missing here? If I query anything past '/html/body' I end up with no result...?
|
It seems you always get a HTML »encapsulation« when using loadHTML and there is not one present. Use »saveXML« to see what's actually in use after loadHTML, that illustrates it best.
-hwh |
| |
|
|