dongmou3615 2019-02-26 11:51
浏览 48
已采纳

PHP - 获取谷歌显示的价格

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;
                }
            }
  • 写回答

1条回答 默认 最新

  • dongzaliang4492 2019-02-26 12:04
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了