NameSilo

Need Google News script

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

jdk

VIP Member
Impact
100
I have a script that used to gather Google news feeds related to a certain keyword. It does not work anymore and I was wondering if anyone can modify this or has a new working on?

PHP:
<?php

$keyword = urlencode($keywords);

set_time_limit(0);

$file = "http://news.google.com/news?sourceid=navclient&ie=UTF-8&rls=GGLG,GGLG:2005-22,GGLG:en&q=$keyword&output=rss";

$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;

function startElement($parser, $name, $attrs) {
       global $rss_channel, $currently_writing, $main;
       switch($name) {
           case "RSS":
           case "RDF:RDF":
           case "ITEMS":
               $currently_writing = "";
               break;
           case "CHANNEL":
               $main = "CHANNEL";
               break;
           case "IMAGE":
               $main = "IMAGE";
               $rss_channel["IMAGE"] = array();
               break;
           case "ITEM":
               $main = "ITEMS";
               break;
           default:
               $currently_writing = $name;
               break;
       }
}

function endElement($parser, $name) {
       global $rss_channel, $currently_writing, $item_counter;
       $currently_writing = "";
       if ($name == "ITEM") {
           $item_counter++;
       }
}

function characterData($parser, $data) {
    global $rss_channel, $currently_writing, $main, $item_counter;
    if ($currently_writing != "") {
        switch($main) {
            case "CHANNEL":
                if (isset($rss_channel[$currently_writing])) {
                    $rss_channel[$currently_writing] .= $data;
                } else {
                    $rss_channel[$currently_writing] = $data;
                }
                break;
            case "IMAGE":
                if (isset($rss_channel[$main][$currently_writing])) {
                    $rss_channel[$main][$currently_writing] .= $data;
                } else {
                    $rss_channel[$main][$currently_writing] = $data;
                }
                break;
            case "ITEMS":
                if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
                    $rss_channel[$main][$item_counter][$currently_writing] .= $data;
                } else {
                    $rss_channel[$main][$item_counter][$currently_writing] = $data;
                }
                break;
        }
    }
}

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($file, "r"))) {
    die("could not open XML input");
}

while ($data = fread($fp, 4096)) {
    if (!xml_parse($xml_parser, $data, feof($fp))) {
        die(sprintf("XML error: %s at line %d",
                    xml_error_string(xml_get_error_code($xml_parser)),
                    xml_get_current_line_number($xml_parser)));
    }
}
xml_parser_free($xml_parser);

// output HTML
// print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . "</div>");

if (isset($rss_channel["ITEMS"])) {
    if (count($rss_channel["ITEMS"]) > 0) {
        for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
            if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
            print ("\n<div class=\"itemtitle\"><a href=\"" . "go.php?url=" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
            } else {
            print ("\n<div class=\"itemtitle\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
            }
             print ("<div class=\"itemdescription\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />");         }
    } else {
        print ("<b>There are no articles in this feed.</b>");
    }
}

?>
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
Close
Thanks but it appears what I had posts still works. For some reason I didnt think it did.
 
0
Close
The following will work as long as you call the page something.php

There are two places to add your keywords - replace CHANGEME with yours. To add more than one word use an + between the words.

Enjoy

Code:
<?php

set_time_limit(0);

$file = "http://news.google.com/news?q=CHANGEME&output=rss";

$rss_channel = array();
$currently_writing = "";
$main = "";
$item_counter = 0;

function startElement($parser, $name, $attrs) {
        global $rss_channel, $currently_writing, $main;
        switch($name) {
             case "RSS":
             case "RDF:RDF":
             case "ITEMS":
                  $currently_writing = "";
                  break;
             case "CHANNEL":
                  $main = "CHANNEL";
                  break;
             case "IMAGE":
                  $main = "IMAGE";
                  $rss_channel["IMAGE"] = array();
                  break;
             case "ITEM":
                  $main = "ITEMS";
                  break;
             default:
                  $currently_writing = $name;
                  break;
        }
}

function endElement($parser, $name) {
        global $rss_channel, $currently_writing, $item_counter;
        $currently_writing = "";
        if ($name == "ITEM") {
             $item_counter++;
        }
}

function characterData($parser, $data) {
     global $rss_channel, $currently_writing, $main, $item_counter;
     if ($currently_writing != "") {
          switch($main) {
               case "CHANNEL":
                    if (isset($rss_channel[$currently_writing])) {
                         $rss_channel[$currently_writing] .= $data;
                    } else {
                         $rss_channel[$currently_writing] = $data;
                    }
                    break;
               case "IMAGE":
                    if (isset($rss_channel[$main][$currently_writing])) {
                         $rss_channel[$main][$currently_writing] .= $data;
                    } else {
                         $rss_channel[$main][$currently_writing] = $data;
                    }
                    break;
               case "ITEMS":
                    if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
                         $rss_channel[$main][$item_counter][$currently_writing] .= $data;
                    } else {
                         $rss_channel[$main][$item_counter][$currently_writing] = $data;
                    }
                    break;
          }
     }
}

$s_URL ='http://news.google.com/news?q=CHANGEME&output=rss';

$r_curl = curl_init();
curl_setopt($r_curl, CURLOPT_URL, $s_URL);
curl_setopt($r_curl, CURLOPT_RETURNTRANSFER, 1);
$s_data = curl_exec($r_curl);
curl_close($r_curl);


$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!xml_parse($xml_parser, $s_data, True))
 {
 die(sprintf("XML error: %s at line %d",
  xml_error_string(xml_get_error_code($xml_parser)),
  xml_get_current_line_number($xml_parser)));
 }
xml_parser_free($xml_parser);

// output HTML
 //print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . "</div>");

if (isset($rss_channel["ITEMS"])) {
     if (count($rss_channel["ITEMS"]) > 0) {
          // for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
          for($i = 0;$i < 5;$i++) {
               if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
               //print ("\n<div class=\"itemtitle\"><a href=\"" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
               } else {
               print ("\n<div class=\"itemtitle\"><b>" . $rss_channel["ITEMS"][$i]["TITLE"] . "</b></div>");
               }
                print ("<div class=\"itemdescription\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div>");           }
     } else {
          print ("<b>There are no new articles.</b>");
     }
}

?>
 
0
Close
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back