By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

parsing html with php5

P: n/a

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:
http://www.ufl.edu/weather

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...?
Aug 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

juicymixx <ju*******@gmail.comwrote:
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);
$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
Aug 28 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.