smallpotato's avatar

Using Symfony DomCrawler to get rss feed

I learned that Laravel is bundled Symfony DomCrawler, which is able to crawl html & xml file. However, I can't collect the RSS date value using DomCrawler filter (this may be caused by my horrible coding). I'm seeking your help to solve my issue.

Below is part of the RSS feed format:

<item>
<title></title>
<description></description>
<pubDate>Wed, 20 Sep 2017 02:03:06 +0800</pubDate>
<guid></guid>
<link></link>
<content:encoded/>
</item>

Below is my Laravel code :

$html = file_get_contents($channel->url);
$crawler = new Crawler();
$crawler->addXmlContent($html);

$items = $crawler->filter('item');
foreach ($items as $item)
{
  $domElement = new Crawler($item);
  $news = new News;
  $news->title = $domElement->filter('title')->text();
  $news->pubDate = $domElement->filter('pubDate')->text();
}

Laravel returned "The current node list is empty.", and located the error is on filtering pubDate tag. Any idea to fix the issue. Thank you.

0 likes
0 replies

Please or to participate in this conversation.