繁体   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