我使用php代码提取ebay会员(合作伙伴网络)rss的标题,但我没有成功。我究竟做错了什么? 顺便说一下,是否也可以链接标题?
PHP
<?php
$xml = new DOMDocument();
@$xml->loadHTMLFile('http://rest.ebay.com/epn/v1/find/item.rss?keyword=%28jewelry%2Ccraft%2Cclothing%2Cshoes%2Cdiy%29&sortOrder=BestMatch&programid=1&campaignid=5337945426&toolid=10039&listingType1=All&lgeo=1&topRatedSeller=true&hideDuplicateItems=true&entriesPerPage=2&feedType=rss');
$products = array();
//Loop through each <td> tag in the dom and extract inner html
foreach($xml->getElementsByTagName('td') as $p) {
$children = $p->childNodes;
$phtml = '';
foreach ($children as $child)
{
$phtml.= $p->ownerDocument->saveHTML($child);
}
echo '<div id="mainproductafilioright1"><div class="product">' . $phtml . '</div></div>';
}
?>
答案 0 :(得分:0)
会发表评论,但没有足够的代表。
该Feed中没有td元素。它也不是HTML文件。
相反:
我是这样做的:
$doc = new DOMDocument();
$doc->loadXML("http://www.longurl.com");
$xpath = new DOMXPath($doc);
$items = $xpath->query("/rss/channel/item/title");
foreach($items as $item) {
if(XML_ELEMENT_NODE === $item->nodeType) {
echo '<div id="mainproductafilioright1"><div class="product">' . $item->textContent . '</div></div>';
}
}
答案 1 :(得分:0)
你正确的方式。在检查Feed页面时,我可以看到td
元素位于<![CDATA[
内。但标题不在其中,这就是为什么你无法获得头衔。
尝试这个临时解决方案(这是一个全新的代码,不能与较旧的代码一起插入):
$feedurl = "http://rest.ebay.com/epn/v1/find/item.rss?keyword=%28jewelry%2Ccraft%2Cclothing%2Cshoes%2Cdiy%29&sortOrder=BestMatch&programid=1&campaignid=5337945426&toolid=10039&listingType1=All&lgeo=1&topRatedSeller=true&hideDuplicateItems=true&entriesPerPage=8&feedType=rss";
$rss = simplexml_load_file($feedurl);
foreach ($rss->channel->item as $item) {
$link = $item->link;
$title = $item->title;
$description = $item->description;
}
您可以使用print
:
print = $description;