0

I am writing a web app and I am trying access a RSS feed from the financial times. However when I run my code I get the following error. I was hoping someone could tell me where I've went wrong.

function getFtRSS(){
    //Create a object to parse XML input from Finanial Time's UK companies RSS feed
    $rssFeed = new DOMdocument();
    //Gather the information and load it into the object
    $rssFeed->load('http://www.ft.com/rss/companies/uk');
    $articles = array();
    //Lookp through all elements in the XML document
    foreach($rssFeed->getElementsByTagName('item') as $newsArtcle){
        $title = $newsArtcle->getElementsByTagName('title')->item(0)->nodeValue;
        $desc = $node->getElementsByTagName('description')->item(0)->nodeValue;
        $link = $node->getElementsByTagName('link')->item(0)->nodeValue;
        $date = $node->getElementsByTagName('pubDate')->item(0)->nodeValue;

        echo   '<li class="list-group-item news-item"  onclick="window.location=\'$link\'">
                    <h3 class=\'top-element\'>$title</h3>
                    <h4>$desc</h4>
                    <h5>$date</h5>
                </li>';
    }
}

I get the following error from my program:

Warning: DOMDocument::load(http://www.ft.com/rss/companies/uk): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /home/ubuntu/workspace/MOT/includes/functions.php on line 46
  • The error says it all. Your script is simply not allowed to load the source url (forbidden by whoever owns that resource). Could be a User-Agent check or similar. – Yoshi Jan 28 '16 at 12:31
  • @Yoshi is right!! Try to fetch the XML file using `cURL` – LefterisL Jan 28 '16 at 12:32

1 Answers1

1

Have you checked the request out of the PHP ? I noticed that they don't accept requests with bad UA check the screenshot below;

Update: Yes they do not accept bad UA, you should change your data fetching method.

User-Agent

Cihan Uygun
  • 2,128
  • 1
  • 16
  • 26