Results 1 to 2 of 2

Thread: A php xpath question?

  1. #1

    Thread Starter
    Addicted Member dim_kevin_as_human's Avatar
    Join Date
    Oct 2005
    Location
    Wisconsin
    Posts
    183

    Question A php xpath question?

    I'm grabbing a page with PHP's cURL and the page contains an arbitarty set of <td> elements in a <table class="content"> how do I use the xpath to traverse to the content class and said td's and match a string, invoke that <td>'s <a href>. I'm just not sure how to set up the xpath and how to search the elements and invoke the a href.

    So..

    the page I parse contains:

    HTML Code:
    -<table class="content">
    --<tbody>
    ---<tr>
    -----<td>
    -----<td>
    -----<td>
    -----<td>
    ---<tr>
    -----<td>
    -----<td>
    ------<a href THIS IS WHAT I NEED TO GRAB IF IT MATCHES>
    ------<br>
    ------<b>THIS IS WHAT I NEED TO SEARCH FOR A MATCH</b>
    ------<br>
    ------Text
    ------<br>
    ------<br>
    -----<td>
    -----<td>
    -----<td>
    this is what i have so far:

    PHP Code:
    $doc = new DOMDocument();
    $doc->loadHTML$rawPage );

    $xpath = new DOMXPath$doc );

    $queryResult $xpath->query"" );
    foreach ( 
    $queryResult as $result )
    {
    echo 
    $result->textContent;

    any help would be appreciated or direction to a really great in-depth xpath or html document parsing guide
    Dreaming men are haunted men.

  2. #2
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    Re: A php xpath question?

    Check out the example in the PHP manual: http://us2.php.net/manual/en/simplexmlelement.xpath.php

    Just curious, what displays when echo $result->textContent; executes?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width