skip to Main Content

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>';      
}
?>

2

Answers


  1. 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>';
        }
    }
    
    Login or Signup to reply.
  2. 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;

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search