How to scrape Google search results for query popularity with PHP

A recent client asked me to find a way to compare the popularity of different articles streaming in via multiple RSS feeds. Since RSS feeds don’t have that kind of information I created this quick demo of a PHP scrapper for Google search queries. The script takes the search terms you wish to use, in our case the title of the news article, cleans it up, assembles it into an URI Google can process, scrapes the results page and then finally uses a bit of regex to strip out the total # of search results. The idea is to then take these results, save them for each RSS entry, compare their values against each other and sort the array from ‘most popular'(ie, most hits) to least. Its just a quick proof of concept demo, but it might come in handy for someone else to extend. Cheers.

';
	echo '

The Search Query (ie, Title of rss post)

'; print_r($query); echo '
'; echo '

Google Result for the query

'; echo $results; echo '
'; echo '

Scraped Total

'; echo $finalResult; echo '
'; echo '
'; print_r($scrape); } fetch_google($query); ?> Return to Main Menu