2015-07-19 74 views
0

我想使用curl獲取信息。獲取信息形式phpdom

大概我得到了所有信息,但我需要單獨獲取信息。

例如,我正在使用curl獲取td文本。

這裏是TD內容

jsfiddle

我需要提取文本 「我的信息」,MyInfo的HREF鏈接和最後的頁碼。

我該怎麼做?

這裏是我的代碼,我使用的捲曲

$nodes = $finder->evaluate('//td[contains(text(), "") and starts-with(@id, "td_threadtitle_") ]'); 
     foreach ($nodes as $node) 
      { 
     $innerHTML = trim($tmp_dom->saveHTML()); 
     $fh = fopen("test.html", 'w'); // we create the file, notice the 'w'. This is to be able to write to the file once. 
     //writing response in newly created file 
     fwrite($fh, $node->c14n()); // here we write the data to the file. 
     fclose($fh); 

    } 

回答

0

我的信息

(//td[starts-with(@id, "td_threadtitle_") ]//a[1]/text())[1] 

它的href

(//td[starts-with(@id, "td_threadtitle_") ]//a)[1]/@href 

末頁數

substring-after(//td[starts-with(@id, "td_threadtitle_") ]//a[. = "Last Page"]/@href, "page=") 
+0

我解決了這個問題,你可以請檢查我的回答是好還是不好?但它的工作正常。 – neo

0

我試過了,這是根據我的要求。

請告訴我這是好還是不好?

$options = $node->getElementsByTagName('a'); 
    $post_message_id=$node->getAttribute('id'); 

     foreach($options as $option) { 
      $value = $option->getAttribute('id'); 

      if($value!=""){ 
       print_r($option->getAttribute('href')); 
       echo "\n"; 
       print_r($option->textContent); 
       echo "\n"; 
       print_r($options->item(($options->length)-1)->getAttribute('href')); 
       echo "\n"; 
      } 

     }