1

I wrote this function to parse through html source code, but for some reason it does not work for feedburner feeds. Any ideas?

$dom = new DOMDocument();
$dom->loadHTMLFile('http://www.killington.com/winter/mountain/conditions');
$xml = simplexml_import_dom($dom);
$snow = $xml->xpath('//td');

What I really need to do is simply get the data from the page.

Bo Hood
  • 11
  • 1
  • 2
  • You need to parse the contents of the feeds themselves (http://feeds.feedburner.com/KillingtonSnowReport) or create feeds from that page? – Erenor Paz Jun 20 '12 at 00:52
  • Pretty much what I am trying to do is take the data from the feed and create a json array. So basically I am trying to take say the number of open trails and store that number in a variable – Bo Hood Jun 20 '12 at 02:46

2 Answers2

1

Not sure what the problem is other than the fact that this isnt a feed its a webpage. That said since youre using dom document theres no reason to bother with simplexml and that may be where the problem is coming in...

$dom = new DOMDocument();
$dom->loadHTMLFile('http://www.killington.com/winter/mountain/conditions');
$xpath = new DOMXPath($dom);
$snow = $xpath->query('//td');
prodigitalson
  • 60,050
  • 10
  • 100
  • 114
  • The url used in my code works, but for some reason if I use a url like: feed://feeds.feedburner.com/KillingtonSnowReport?format=xml it returns nothing. – Bo Hood Jun 20 '12 at 02:40
  • Well thats because there arent any `td` elements in a feed... did you look at the XML to see what you were parsing????? – prodigitalson Jun 20 '12 at 10:15
  • Yes, I was lazy and copied the code that worked for me for the original http url, I tried using different tag lines that were in the xml on the feed but that didn't work – Bo Hood Jun 20 '12 at 20:08
1

First of all, you must open the feed page (the xml one, for example) and check which kind of feed it is:

<rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

Then, you take a look at something like this good tutorial: http://net.tutsplus.com/articles/news/how-to-read-an-rss-feed-with-php-screencast/ and you're almost done :)

Erenor Paz
  • 3,061
  • 4
  • 37
  • 44
  • 1
    What exactly does this line of code do? I was thinking the problem may be because feedburner may use a different port than say http – Bo Hood Jun 20 '12 at 02:44
  • That line of code is one of the many you can find in the xml page of the feed. It's just one that gives you hint about how to procede to get the feeds. Why? Because there are many kind of feeds, and each one has different tags, so you must parse it in a different way :) – Erenor Paz Jun 20 '12 at 10:07
  • I hope you’re aware that this link-only answer doesn’t help… at all, because the linked article doesn’t mention namespaces or how to handle them. – e-sushi Oct 30 '17 at 12:44