-1

I'm using a php code to extract the title of an ebay affiliate (Partner Network) rss, but I'm having no success. What am I doing wrong? By the way, is it possible to link the title too?

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>';      
}
?>
ArK
  • 20,698
  • 67
  • 109
  • 136
User325313
  • 79
  • 9
  • 1
    Uhhhh `getElementsByTagName('td')` seeing your are getting an RSS feed there are no `td` tags ... you just copied some code and didn't edit it at all to do what you wanted it to do. – cmorrissey Aug 25 '16 at 19:49
  • It's because that's an old code I had configured before for another rss. – User325313 Aug 25 '16 at 19:54

2 Answers2

0

Would comment but not enough rep.

There are no td elements in that feed. It's also not an HTML file.

Instead:

  • Load as XML
  • Create XPath expression to select title nodes
  • Iterate returned nodes and make sure they're actual DOM nodes
  • Extract text value of node.

Here's how I'd do it:

$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>';
    }
}
0

You're on the right way. While checking the feed page I could see that the td elements are inside the <![CDATA[. but the title is outside it, that's why you can't get the title.

Try this temporary solution (This is a completely new code, not to be inserted with the older one):

$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;

}

You can output it using print:

print = $description;