0

I would like to recover all price from Google search in a PHP file.

Exemple of price search : https://www.google.com/search?ei=QBN1XIfYDrG5gwfmq6bwDg&q=860+evo+500go&oq=860+evo+500go&gs_l=psy-ab.3..0j0i10j0i22i10i30j0i22i30l3.5044.6363..6572...0.0..0.59.347.6......0....1..gws-wiz.......0i71j0i20i263j0i67j0i203.HYjd3deC288

file_get_contents doesn't work and i've to use CURL like in this topic :

PHP file_get_contents error 503

Now i dunno how to create next of script.

I guess I have to create a loop and use the function preg_match to keep only what i need.

It is right ? Can i've any exemple ?

Here is the beginning of my script :

            $url = "https://www.google.com/search?ei=QBN1XIfYDrG5gwfmq6bwDg&q=860+evo+500go&oq=860+evo+500go&gs_l=psy-ab.3..0j0i10j0i22i10i30j0i22i30l3.5044.6363..6572...0.0..0.59.347.6......0....1..gws-wiz.......0i71j0i20i263j0i67j0i203.HYjd3deC288";

            function curl_get_file_contents($URL) {
                $c = curl_init();
                curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
                curl_setopt($c, CURLOPT_URL, $URL);
                $contents = curl_exec($c);
                curl_close($c);

                if ($contents) return $contents;
                else return FALSE;

                foreach ($variable as $key => $value) {

                    echo $result;
                }
            }
  • How many of these searches will you be making? [Google's Custom Search API](https://developers.google.com/custom-search/v1/overview) might be a better solution if you are making 100 queries or less daily. – tshimkus Feb 26 '19 at 11:58
  • What are you expecting to loop through when this returns the contents of a search page? – tshimkus Feb 26 '19 at 12:00
  • the goal of my project is to compare prices over several months. So I need to save the price once a month for example in bdd. So I will be able to know if it is interesting for me to buy new material for my personal computer according to the time of the year. – tartenpion Feb 26 '19 at 18:15

1 Answers1

0

This will not work reliably. Google search is quite sensitive to scraping and quickly starts to respond with request to verify captcha when it suspects automated access.

I would recommend to look into a better source for information you need, otherwise you just risk burning time on writing code that won't run because you can't consistently get your data in first place.

Rarst
  • 2,335
  • 16
  • 26