[英]Can't extract rss feed item title
我正在使用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>';
}
?>
會發表評論,但代表不足。
該供稿中沒有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>';
}
}
您的方法正確。 在檢查提要頁面時,我可以看到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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.