Jump to content



Welcome to AstaHost - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!

Toggle shoutbox Shoutbox Open the Shoutbox in a popup

@  yordan : (19 June 2013 - 02:28 PM) Long Life To Asta New Era
@  agyat : (19 June 2013 - 01:58 PM) New Era Start At Asta Or Asta Start In New Era. :unsure:
@  yordan : (16 June 2013 - 05:41 PM) You're Welcome, Agyat!
@  agyat : (16 June 2013 - 07:38 AM) Thanks Yordan...
@  velma : (16 June 2013 - 12:06 AM) I Have Asked Opa To Check For A Backup.. He'll Let Me Know Soon :)
@  velma : (16 June 2013 - 12:05 AM) T_T It Seems That Someone Has Deleted That Topic Since I Found The Url Of The Topic But It Gives Me An Error
@  yordan : (15 June 2013 - 10:31 PM) @velma : It's A Tuto On How To Create A Login Program.
@  yordan : (15 June 2013 - 10:31 PM) Happy Birthday To Youuuuuu Agyat!
@  yordan : (15 June 2013 - 10:31 PM) Ba$
@  agyat : (15 June 2013 - 04:41 PM) :(
@  agyat : (15 June 2013 - 04:41 PM) Where The Hall I Were? 15Th Is Almost At End And No-One Wished Me "happy Birthday"!!!
@  velma : (14 June 2013 - 10:39 AM) Which Tutorial Is He Searching For?
@  velma : (14 June 2013 - 10:38 AM) Which Tutorial Is He Searching For?
@  yordan : (14 June 2013 - 07:47 AM) Ok, Have A Look Tomorrow.
@  yordan : (13 June 2013 - 03:19 PM) @velma, Can You Have A Look At Feelay's Problem? Seems That His Tutorial Is Not Searchable Today.
@  Feelay : (13 June 2013 - 08:11 AM) Oh, Haha
@  velma : (12 June 2013 - 05:39 PM) T_T Lately My Levels Of Procrastination..... **sigh**
@  velma : (12 June 2013 - 05:38 PM) I'll Do It Later
@  velma : (12 June 2013 - 05:38 PM) Procrastinators.. People Who Keep Saying "i'll Do This In A Bit"
@  Feelay : (12 June 2013 - 02:05 PM) Deal Punishments To What?

Photo
- - - - -

Operating On Google News


No replies to this topic

#1 Pavarr

Pavarr

    Newbie [ Level 1 ]

  • Members
  • 8 posts

Posted 28 January 2006 - 01:53 PM

First of all, we have to store our Google news in variable:

$googlenews = file("http://news.google.com/news/en/us/world.html");

Then, we get ourselves a table, containing news' link with title, popularity on Google News, how old is the news, and where it has been found by Google:

$popularity = 0; // table index

for($i = 46; $i < count($googlenews); $i++){ // real news start at line 46

$all = explode("<font size=",$googlenews[$i]); // it makes it easier to retrieve headers

for($j = 0; $j < count($all); $j++){

$act = $all[$j]; // actual current chunk

// a bit of cleaning up
$act = str_replace("</tr>","",$act);
$act = str_replace("</td>","",$act);
$act = str_replace("</table>","",$act);
$act = str_replace("</b>","",$act);
$act = str_replace("</font>","",$act);
$act = str_replace("<nobr>","",$act);
$act = str_replace("&nbsp;","",$act);
$act = str_replace("<br>","",$act);

// enough cleaning

if(stristr($act, "-1>") && stristr($act, "<font color=#6f6f6f>")){ // checking for markers of _real_ news

	$where_time = str_replace("-1><font color=#6f6f6f><b>","",$act); // getting where and time as one string
	$gdzie_czas = str_replace("</nobr>","",$gdzie_czas); // another cleaning routine

	$where_time_arr = explode("- ",$where_time); // dividing to time and source
	$popularity++; // getting current table index
        
        $where = $where_time_arr[0];
        $time = $where_time_arr[1];
        // we know now where news was found, let's get news title & link

	$news = explode('<td valign=top>',$all[$j-1]);  // right things be right :)
        $true_news = $news[1];
	$news_array[$jak_dawno] = $where.'|'.$time.'|'.$true_news; // table input
}
}
}

Now, that we have got the array with pure information, we can do virtually everything with it, for example:

foreach($news_array as $value){
       $values_arr = explode("|",$value);
       $where = $values_arr[0];
       $time = $values_arr[1];
       $news = $values_arr[2];
       echo "$news - found in $where $time<br/>";
}

We can also search it for keywords, or do with it something like that.

I have to add, I haven't yet developed a simple and always-working way to exclude the link from the news title - sometimes there is unknown bug and there are residual chars form link :/ But even without it, it's fully functional.



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users