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;
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 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 ??

Link to comment
Share on other sites

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.