Scraping google SERPs

stash

Newbie
Joined
Mar 28, 2008
Messages
10
Reaction score
0
looking for script that will scrape top 10 google search results for a keyword and then insert the results in text format to pages. would work on pages that are php and would need to look up the results based on the php ID.

any help appreciated
 
make your own dude, it's very easy
hxxp://www.oooff.com/php-scripts/php-scraping-scripts.php
 
Here is a script that scrapes top 10 results from google for the desired keyword and stores the results in a text file.
Code:
$keyword = urlencode('keyword you want to search for');

$url = "http://www.google.com/search?q=".$keyword."&num=10&hl=en&start=0&sa=N";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$webpage = curl_exec($ch);
curl_close($ch);
preg_match_all("/<h3 class=r><a href=\"(.*?)\" class=l onmousedown=\"(.*?)\">(.*?)<\/a>/",$webpage,$match);

$size = (sizeof($match[1]) -1);
for ($i = 1; $i <$size ; $i++)     //60 Articles
  {
		$foundLinks[] = $match[1][$i];	
  		
  }
  foreach ($foundLinks as $links)
  {
  	fwrite($fh, $links);
  	fwrite($fh, "\r\n");
  }
  fclose($fh);
 
@ unknow_zero.

Yeah i think i find a lot of shit over there. thanks anyway
 
If this is for automatic content generation, maybe you should consider the MSN Live Search API. It is much more flexible and you won't get banned for "automatic" requests like Google. You can get more info at
http://dev.live.com/livesearch/
 
Google banned me in 3 different states! just for gathering data 3x/ 4days a week. They also banned a friend of mine in antoher state. I wasn't scraping jsut using an automaeted tool(s) to gather serp data.

NOTE: By banned i mean they screw with the SERP really badly (for me only).

For example: I'm on "page 20"... however if you check from any other computer it's page 3.

They do this so I can't see which SEO techniques are working. Though they have only done this to 1 website of mine???
 
sign up for a free account with google alerts - the rest will become obvious

demon you possibly experiencing the google dance...
 
2 Firefox addons

Download SEOquake to provide data and download into txt or CSV Files
Download FLEM This loads txt files into Firefox

Step 1 - Type any keyword into google or a few keywords

Step 2 - Copy google's URL and paste it into an excel Sheet
I tried putting the full search string but didn't come up for some reason

Step 3 - Split the URL, copy the first part of the URL up until your first keyword and put in a seperate cell
http://www.google.com/search?hl=en&num=100&q=

Step 4 make cells for each keyword all starting with a + sign

Step 5 paste the end of the google URL into the cell.
&cts=1266480684079&aq=f&aqi=&oq=

Step 6 - place all keywords in those cells and copy and paste google's URL to match the amount of keywords you have

Step 7 - Copy and paste the whole lot into notepad and save

Step 8 - Load your new text file into FLEM and push next

Step 9 - Use SEOQuake to save the results (should be above the first result)

Step 10 - Enjoy

Sorry for the amount of steps just wanted to make it easy to understand. If you know imacro's or something then you could possibly make this fully automated. FLEM also allows a slideshow which means it will press next for you at intervals you setup.
You can also set SEOquake to show as much or as little data you want. So if you only want URL's or if you want the full works (PR, backlinks ect) it's up to you.
 
Last edited:
2 Firefox addons

Download SEOquake to provide data and download into txt or CSV Files
Download FLEM This loads txt files into Firefox

Step 1 - Type any keyword into google or a few keywords

Step 2 - Copy google's URL and paste it into an excel Sheet
I tried putting the full search string but didn't come up for some reason

Step 3 - Split the URL, copy the first part of the URL up until your first keyword and put in a seperate cell
http://www.google.com/search?hl=en&num=100&q=

Step 4 make cells for each keyword all starting with a + sign

Step 5 paste the end of the google URL into the cell.
&cts=1266480684079&aq=f&aqi=&oq=

Step 6 - place all keywords in those cells and copy and paste google's URL to match the amount of keywords you have

Step 7 - Copy and paste the whole lot into notepad and save

Step 8 - Load your new text file into FLEM and push next

Step 9 - Use SEOQuake to save the results (should be above the first result)

Step 10 - Enjoy

Sorry for the amount of steps just wanted to make it easy to understand. If you know imacro's or something then you could possibly make this fully automated. FLEM also allows a slideshow which means it will press next for you at intervals you setup.
You can also set SEOquake to show as much or as little data you want. So if you only want URL's or if you want the full works (PR, backlinks ect) it's up to you.

Thanks man! Can you share link download SEOquake tools, i finding it along time but not see anywhere!
 
http://google-scraper.squabbel.com

This contains all information you need to scrape google, tells you how to avoid their detection and contains an advanced scraper (PHP) that was already used to scrape a few million hits without any banning problem.

That's the right source for people who want to professional scrape SERP data and either know a bit PHP or have a programmer to customize the work.
I'd add mysql support for example.
 
Google banned me in 3 different states! just for gathering data 3x/ 4days a week. They also banned a friend of mine in antoher state. I wasn't scraping jsut using an automaeted tool(s) to gather serp data.

NOTE: By banned i mean they screw with the SERP really badly (for me only).

For example: I'm on "page 20"... however if you check from any other computer it's page 3.

They do this so I can't see which SEO techniques are working. Though they have only done this to 1 website of mine???

Uhhm.. have you tried logging out of google and clearing your cookies? also Some ISPs now offer the ability to update your ip id ask yours.
 
Im looking for a list of forums I can join that have either the words Boston,Taxi,Cab or a combo or 2 or all three in their domains. IF you get really bored you can list them in a spread sheet with a direct link to the signup pages and if you are really bored you can list them in descending order of page rank of the main page.
 
Here is a script that scrapes top 10 results from google for the desired keyword and stores the results in a text file.
Code:
$keyword = urlencode('keyword you want to search for');

$url = "http://www.google.com/search?q=".$keyword."&num=10&hl=en&start=0&sa=N";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$webpage = curl_exec($ch);
curl_close($ch);
preg_match_all("/<h3 class=r><a href=\"(.*?)\" class=l onmousedown=\"(.*?)\">(.*?)<\/a>/",$webpage,$match);

$size = (sizeof($match[1]) -1);
for ($i = 1; $i <$size ; $i++)     //60 Articles
  {
        $foundLinks[] = $match[1][$i];    
          
  }
  foreach ($foundLinks as $links)
  {
      fwrite($fh, $links);
      fwrite($fh, "\r\n");
  }
  fclose($fh);
Thanks bro but I think your code has stopped working. the reason could be now google use ajax to generate the results, not plain html anymore.
 
Thanks bro but I think your code has stopped working. the reason could be now google use ajax to generate the results, not plain html anymore.

Technically, you can still use cURL to scrape Google serps. While Google has modified their algorithm their search results are still in plain html. As a result you can use PHP's cURL to scrape the results.
 
Back
Top