parsing html with php5

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • juicymixx

    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:
    404 Not FoundOops! It appears that the page you are looking for isn't here.Shall we go back to the homepage and have a look around?


    I've tried several options, but am currently working on:
    $url = 'http://www.ufl.edu/weather';
    $dom = new DOMDocument();
    $doc->validateOnPars e = true;
    $dom->loadHTML($url) ;
    $xpath = new DOMXPath($dom);
    $result = $xpath->query("/html/body/div[@id='mainContai ner']/div/
    table");

    What am I missing here? If I query anything past '/html/body' I end
    up with no result...?
  • Hans-Werner Hilse

    #2
    Re: parsing html with php5

    Hi,

    juicymixx <juicymixx@gmai l.comwrote:
    I've tried several options, but am currently working on:
    $url = 'http://www.ufl.edu/weather';
    $dom = new DOMDocument();
    $doc->validateOnPars e = true;
    $dom->loadHTML($url) ;
    that line should be
    $dom->loadHTMLFile($ url);
    $xpath = new DOMXPath($dom);
    $result = $xpath->query("/html/body/div[@id='mainContai ner']/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

    Comment

    Working...