Jump to content

Recommended Posts

I want to make a feed that goes to other websites and updates when they post a story. Not immediately, but just around the same time. I guess a better way to describe it would be i want a news feed that populates from other news feeds. The only way I can imagine this working is ajax that reads data from the pages in intervals and knows where to start looking for information and a table that logs the last information so it doesn't repeat.

 

Is there a better way to do this?

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/139688-creating-a-news-feed-from-other-sites/
Share on other sites

If you need to grab lets say a block of text from a page you could use CURL to get the page, then a series of regular expressions to extract the portion of the page that you require. You will need delimeters to specify where the blocks start and end (maybe a set of div tags within the HTML)

I do not know how to harvest data from websites when I have no access to their code

 

Why do you need access to code? If you can see information on-screen then you can grab it.

 

Because the way I'd optimally want them to do it is have their updates write to my xml file. I want my news feed to update when they update theirs.

 

If you need to grab lets say a block of text from a page you could use CURL to get the page, then a series of regular expressions to extract the portion of the page that you require. You will need delimeters to specify where the blocks start and end (maybe a set of div tags within the HTML)

 

I'd still need to ajax to their site in regular intervals, no?

You'd likely want to use Cron.  Most RSS feeds update once an hour.

 

I have no idea what cron is after looking at it's wiki page. Well I do, but I have no idea how I'd ever implement it. I mean, the sites I'm fetching data from don't all have rss feeds.

There are all sorts of ways to do this.  Are you using a database?  For the sites that have RSS feeds, that's simple, just parse the feeds and display on your site.  If you want to make it AJAXy that's your decision, but it doesn't have to, it could just update on pageload.  For site's that don't use RSS, you will need to use CURL (if your server supports opening remote files, you can use file_get_contents) to grab the HTML and parse it for the news articles using regular expressions.

I would just google 'php curl' and you will find tons of examples.  You will need to simply get the contents of a web page as a string.  So something like this should work:

 

<?php
$ch = curl_init();

// there are a lot of other CURL options you might want to check out
// http://us2.php.net/manual/en/function.curl-setopt.php
curl_setopt($ch, CURLOPT_URL, "http://www.myurl.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);

curl_close($ch);

echo $result;
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.