Jump to content

HELP!how to get the URL of a google search result without using API


jigen7

Recommended Posts

I might as well give you the whole thing .. keep in mind that this may break each time google subtly alters their SERP format.

 

<?php
function fetch_google_results($content) {

  $parser = new HtmlParser($content);
  $display = false;
  $rank = 0;
  $urls = array();
  while ($parser->parse()) {
    if ($parser->iNodeType == NODE_TYPE_ELEMENT
     && $parser->iNodeName == 'blockquote'
     && $parser->iNodeAttributes['class'] == 'g') {
      /* Find the end of the blockquote */
      while ($parser->parse()) {
        if ($parser->iNodeType == NODE_TYPE_ENDELEMENT
         && $parser->iNodeName == 'blockquote') {
          break;
        }
      }
    }
    if ($parser->iNodeType == NODE_TYPE_ELEMENT
     && $parser->iNodeName == 'div'
     && $parser->iNodeAttributes['class'] == 'g') {
      while ($parser->parse()) {
        if ($parser->iNodeType == NODE_TYPE_ELEMENT
         && $parser->iNodeName == 'a') {
          break;
        }
      };
      $url = $parser->iNodeAttributes['href'];
      if ($url == '') continue;
      $rank++;
      $urls[$rank]['url'] = $url;
      // print "$rank: $url\n";

      /* Title can contain bold tags.  Identify it by anchor tags */
      $title = '';
      while ($parser->parse()) {
        if ($parser->iNodeType == NODE_TYPE_ENDELEMENT
         && $parser->iNodeName == 'a') {
          break;
        }
        if ($parser->iNodeType == NODE_TYPE_TEXT) {
          $title .= $parser->iNodeValue;
        }
      }
      $urls[$rank]['title'] = $title;

      /* Fetch the extract from the page itself */
      /* We stop when we find a <td> */
      while ($parser->parse()) {
        if ($parser->iNodeType == NODE_TYPE_ELEMENT
         && $parser->iNodeName == 'td') {
          break;
        }
      }
      $parser->parse(); /* <font size="-1"> */
      $description = '';
      while ($parser->parse()) {
        /* Ends with a span tag */
        if ($parser->iNodeType == NODE_TYPE_ELEMENT
         && $parser->iNodeName == 'span') {
          break;
        }
        if ($parser->iNodeType == NODE_TYPE_TEXT) {
          $description .= $parser->iNodeValue;
        }
      }
      $urls[$rank]['description'] = $description;
    }
  }

  return $urls;
}

Just use the following link...

 

http://www.google.ca/search?hl=en&q=this+is+my+search&btnG=Google+Search&meta=

so

http://www.google.ca/search?hl=en&q=this+is+my+search&btnG=Google+Search&meta=

 

Language is BLUE

Search text is LIME GREEN, words separated by +

Submit button is PINK, this is important as the search page will not display results with out this.

  • 3 weeks later...

Just use the following link...

 

http://www.google.ca/search?hl=en&q=this+is+my+search&btnG=Google+Search&meta=

so

http://www.google.ca/search?hl=en&q=this+is+my+search&btnG=Google+Search&meta=

 

Language is BLUE

Search text is LIME GREEN, words separated by +

Submit button is PINK, this is important as the search page will not display results with out this.

 

 

So how is it possible to filter the links ??

 

By using Regex ??

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.