See if page cached using php

by 71667
7 replies
Hi

I've been looking for a bit to find a php function or class which will return if a web page is cached or not by Google.

Would prefer to use the google API as opposed to scraping.

Does anyone have a snippet they are prepared to share ?

Thanks
Brian
#cached #page #php
  • Profile picture of the author Bruce Hearder
    Unfortunately the Google API is no longer available.
    The old codes still work, but new user cannot signup any more! Bummer!!

    The google cache dates are notoriusly unreliable!
    Just check some of the threads on seo roundtbale forum, and you will see what I mean.

    Its not uncommon for you to check a cache date on one day, and then a couple of days later you check again, and find that the cache date has gone backwards!

    Unfortunately I know of no easy way to get the cache date, other than scraping the G pages for the info..

    Sorry i can't help more

    Bruce
    {{ DiscussionBoard.errors[1276184].message }}
    • Profile picture of the author 71667
      Thanks for the quick reply.

      I'm not too worried about the cache date just want to know its indexed & was going to use the fact its cached to do the job.

      Working on a script which will tell me if a link back to my site is on a page which is indexed by Google.

      Is there a better way of doing this

      Thanks
      Brian
      {{ DiscussionBoard.errors[1276195].message }}
  • Profile picture of the author Bruce Hearder
    If all you want to know that its is indexed, then why not just do a :

    site: yourdomain.com

    If you get results, then your site is indexed.
    I use this with my http://findlinkpartners.com site. Where a site only gets included if its indexed, and gets dropped when its no longer indexed..

    Would this concept work for you

    Bruce
    {{ DiscussionBoard.errors[1276208].message }}
  • Profile picture of the author 71667
    Yes - your right

    Thanks
    {{ DiscussionBoard.errors[1276424].message }}
  • Profile picture of the author 71667
    Sorry Should have asked - do you screen scrape or use the Google API.

    If API any chance of a code snippet ?
    {{ DiscussionBoard.errors[1276462].message }}
    • Profile picture of the author Bruce Hearder
      Sure..

      First I have to admit that my regex expertise is not the best, but it works.

      Plus, I use Snoopy, you could use cURL or whatever you like to get the code back from G!
      /* returns -1 if nothing found, otherwise a number >0 */
      function get_number_pages_in_goole($url='')
      {
      if($snoopy->fetch('http://www.google.com/search?q=site:'.urlencode($url)))
      {
      $page = $snoopy->results;
      preg_match('|Results <[^>]+>(.*)</[^>]+> - <[^>]+>(.*)</[^>]+> of <[^>]+>(.*)</[^>]+> |U',$page,$matches);

      if (!isset($matches[3]))
      preg_match('|Results <[^>]+>(.*)</[^>]+> - <[^>]+>(.*)</[^>]+> of about <[^>]+>(.*)</[^>]+> |U',$page,$matches);
      if (!isset($matches[3]))
      $m=-1;
      else
      {
      $n=$matches[3];
      $n = str_replace(',','',$n);
      $m = intval($n);
      }
      }
      return $m;
      }

      Hope this helps

      Bruce
      {{ DiscussionBoard.errors[1278007].message }}
  • Profile picture of the author 71667
    Thanks Bruce - Helps a lot
    {{ DiscussionBoard.errors[1278637].message }}

Trending Topics