簡體   English   中英

PHP DOMXpath不抓取URL

[英]PHP DOMXpath not scraping URL

我正在嘗試獲取這些標簽之間的數據:

<item><title>White Paper and Sales copy writer by stelladonsai</title>
<link>http://www.freelancer.com/projects/Technical-Writing-Academic-Writing/White-Paper-Sales-copy-writer.html</link>
<description>I need native English speaker to write a piece of white paper and a Sales copy.    *you must have experience.   *you must be native English speaker  *you must have sample to be attached with your cover... (Budget: &#36;30-&#36;250 USD, Jobs: Academic Writing, Technical Writing)</description>
<pubDate>Thu, 18 Oct 2012 17:23:10 -0400</pubDate>
<guid isPermaLink="false">Freelancer.com_project_2578329</guid>
</item>

我正在使用的PHP代碼是:

$html = new DOMDocument();
@$html->loadHTML($txt);
$xpath = new DOMXPath( $html );

/*Begin Get Titles*/
$bquery = $xpath->query( "//item/title" );
$i=0;
foreach ($bquery as $b){
    $i=$i+1;
    $title[$i] = $b->nodeValue; 
}
/*End Get Titles*/

/*Begin Get Links*/
$bquery = $xpath->query( "//item/link" );
$i=0;
foreach ($bquery as $b){
    $i=$i+1;
    $link[$i] = $b->nodeValue;  
}
/*End Get Links*/

$ txt來自我用CURL抓取的RSS feed。 上面的代碼獲得的標題以及我想要的任何其他字段都很好。 但是,當我嘗試刮擦並回顯鏈接字段時,我什么也沒回來。 (我嘗試用其他字段替換// item / link,它們都起作用了)。

不知道我在這里做錯了什么,所有幫助將不勝感激。

使用loadXML ,而不是loadHTML為您加載XML而不是HTML。

http://codepad.org/0FYXiwMy

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM