Google Search: Copy Results Page in PHP for Total Results

Is it possible to clear the Google search results page using PHP to display the total number of search results found?

If so, how do I do this?

thanks

+4
source share
4 answers

try using phpsimplehtmlparser

$search_query = 'google'; $url = sprintf('http://www.google.com/search?q=%s', $search_query); $html = file_get_html($url); $results = $html->find('#resultStats/b', 2)->innertext; echo sprintf('Google found %s results for "%s"', $results, $search_query); 
+6
source

This PHP class does this: http://www.phpclasses.org/browse/package/3924.html

"You can use this class to get the total number of results for a given Google search query.

He turns to the Google search site to fulfill a query for a given search term.

The class parses the results page and extracts the total number of results that the given query was returned. "

+5
source

You will need a bunch of proxies depending on the number of requests you plan to send. You can send about 500 requests per day and IP / proxy without causing problems or detection.

You should read google-rank-checker.squabbel.com article containing a full-featured scraper in PHP. Use this scraper, modify it according to your requirements and add the phpsimplehtmlparser code (another answer) to get general information about the results for keywords.

I suggest using libCURL to access Google itself. You will have more options than using a simpler API, you will not have much fun working with file_frames or similar internal php functions, since Google will block your script soon.

Something like that:

  curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER , 1); $curl_proxy = "$IP:$PORT"; curl_setopt($ch, CURLOPT_PROXY, $curl_proxy); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); curl_setopt($ch, CURLOPT_TIMEOUT, 20); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en; rv:1.9.0.4) Gecko/2009011913 Firefox/3.0.6"); $url = sprintf('http://www.google.com/search?q=%s', $keyword); curl_setopt ($ch, CURLOPT_URL, $url); $htmdata = curl_exec ($ch); 

Now just use regex () / substr () / strstr () to grab data from $ htmldata p>

+2
source

I use this php script to find out the final results of my name in a google search.

<?php
$homepage = file_get_contents('http://www.google.co.in/search?ix=nh&sourceid=chrome&ie=UTF-8&q=Mohit+dabas');
preg_match('/(About )?([\d,]+) result/si', $homepage, $p) ;
echo $p[0];
?>

the main thing to notice is the '& q' parameter in the above path

My name contains a space, so the browser added "+" to it

So, you should check the ur query (ie & q) parameters, and if the ur request contains some special

e.g..,:,%, etc., then you should note how they are processed by the browser and

change the parameters acc. to your int script need.

srry for poor english

+1
source

Source: https://habr.com/ru/post/1305759/


All Articles