Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » PHP

parsing html with php5

 
Jump to:  
 
juicymixx
PostPosted: 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
PostPosted: 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
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

gry i zabawy Świat zwierząt. 1000 pytań i odpowiedzi dream dictionary opony matador Tusz Epson black DoublePack DURABrit