3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Author: Yash Gupta | File: search.php Complete code source and tutorial: http://thetechnofreak.com/technofreak/get-scrape-google-search-results-php/ Description: This script searches google for a given search term and outputs all the results' urls for up to 1000 results. Usage: Make a form in some other page and pass the following parameters with GET method, or modify the url as search.php?pages=50&q=get+google+results+php q => Your search query. Default query is: 'no query' pages => The number of pages you want to parse. (default is 10, maximum of 100) start => The page to start from. Default is 1 10/04/2012 mods/fixes/updates by Jay at http://he.tel */ echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Scrape Google Results with PHP</title> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> </head> <body>'; $input=rawurldecode($_GET["input-text"]); $keyword=trim(preg_replace("/\s\s+/", " ", $input)); if (isset($_GET["data"])){ echo "Your Search Term ==> <b>"; print_r(htmlspecialchars($keyword)); echo "</b><br><br><br>"; if(substr($_SERVER['DOCUMENT_ROOT'],0,2)==="C:"){ echo '<a href="http://localhost'.$_SERVER['PHP_SELF'].'">Reset Search</a>'; }else{ echo '<a href="'.$_SERVER['PHP_SELF'].'">Reset Search</a>'; }} echo '<br> <br> <center>'.PHP_EOL; echo '<form action="search.php?&pages=10&q='.$keyword.'&method="get">'.PHP_EOL. '<input type="text" name="input-text" size="60%"/>'.PHP_EOL. '<input type="submit" name="data" value="Web Search"/>'.PHP_EOL.'</form>'.PHP_EOL; echo '</center> <pre> <br>'; if (isset($_GET["data"])){ ini_set("max_execution_time", 0); set_time_limit(0); // no time-outs! if(isset($_GET['q'])) $query=$_GET['q']; else $query=$keyword; if(isset($_GET['pages'])) $npages=$_GET['pages']; else $npages=10; if(isset($_GET['start'])) $start=$_GET['start']; else $start=0; if($npages>=100) $npages=100; $gg_url='http://www.google.com/search?hl=en&safe=off&filter=0&q='.urlencode($query).'&start='; $i=1; $size=0; $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects CURLOPT_COOKIEFILE => "cookie.txt", CURLOPT_COOKIEJAR => "cookie.txt", CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0", CURLOPT_REFERER => "http://www.google.com/"); for ($page = $start; $page < $npages; $page++){ $ch = curl_init($gg_url.$page.'0'); curl_setopt_array($ch,$options); $scraped=""; $scraped.=curl_exec($ch); curl_close($ch); $results = array(); preg_match_all('/a href="([^"]+)" class=l.+?>.+?<\/a>/',$scraped,$results); foreach ($results[1] as $url){ echo " <a href='$url'>$url</a>".PHP_EOL; $i++; } $size+=strlen($scraped); } @fclose($fp); $Num=$i-1; echo "<br><br>Number of results: ".$Num.PHP_EOL; echo "Total KB read: ".($size/1024.0).PHP_EOL; } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 47
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 42
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 187
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 72, Position 2 = 76
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 84
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
2 jumps found. (Code = 43) Position 1 = 88, Position 2 = 92
Branch analysis from position: 88
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
2 jumps found. (Code = 43) Position 1 = 95, Position 2 = 96
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 171
Branch analysis from position: 171
2 jumps found. (Code = 44) Position 1 = 173, Position 2 = 131
Branch analysis from position: 173
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 131
2 jumps found. (Code = 77) Position 1 = 157, Position 2 = 167
Branch analysis from position: 157
2 jumps found. (Code = 78) Position 1 = 158, Position 2 = 167
Branch analysis from position: 158
1 jumps found. (Code = 42) Position 1 = 157
Branch analysis from position: 157
Branch analysis from position: 167
2 jumps found. (Code = 44) Position 1 = 173, Position 2 = 131
Branch analysis from position: 173
Branch analysis from position: 131
Branch analysis from position: 167
Branch analysis from position: 96
Branch analysis from position: 92
2 jumps found. (Code = 43) Position 1 = 95, Position 2 = 96
Branch analysis from position: 95
Branch analysis from position: 96
Branch analysis from position: 84
2 jumps found. (Code = 43) Position 1 = 88, Position 2 = 92
Branch analysis from position: 88
Branch analysis from position: 92
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 84
Branch analysis from position: 80
Branch analysis from position: 84
Branch analysis from position: 187
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 187
Branch analysis from position: 62
Branch analysis from position: 187
Branch analysis from position: 47
filename:       /in/YngN7
function name:  (null)
number of ops:  188
compiled vars:  !0 = $input, !1 = $keyword, !2 = $query, !3 = $npages, !4 = $start, !5 = $gg_url, !6 = $i, !7 = $size, !8 = $options, !9 = $page, !10 = $ch, !11 = $scraped, !12 = $results, !13 = $url, !14 = $fp, !15 = $Num
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ECHO                                                     '%3C%21DOCTYPE+html+PUBLIC+%22-%2F%2FW3C%2F%2FDTD+XHTML+1.0+Transitional%2F%2FEN%22+%22http%3A%2F%2Fwww.w3.org%2FTR%2Fxhtml1%2FDTD%2Fxhtml1-transitional.dtd%22%3E%0A++++%3Chtml+xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%0A++++%3Chead%3E%0A++++%3Ctitle%3EScrape+Google+Results+with+PHP%3C%2Ftitle%3E%0A++++%3Cmeta+http-equiv%3D%22Content-type%22+content%3D%22text%2Fhtml%3B+charset%3Dutf-8%22+%2F%3E%0A++++%3C%2Fhead%3E%0A++++%3Cbody%3E'
   21     1        INIT_FCALL                                               'rawurldecode'
          2        FETCH_R                      global              ~16     '_GET'
          3        FETCH_DIM_R                                      ~17     ~16, 'input-text'
          4        SEND_VAL                                                 ~17
          5        DO_ICALL                                         $18     
          6        ASSIGN                                                   !0, $18
   22     7        INIT_FCALL                                               'trim'
          8        INIT_FCALL                                               'preg_replace'
          9        SEND_VAL                                                 '%2F%5Cs%5Cs%2B%2F'
         10        SEND_VAL                                                 '+'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $20     
         13        SEND_VAR                                                 $20
         14        DO_ICALL                                         $21     
         15        ASSIGN                                                   !1, $21
   23    16        FETCH_IS                                         ~23     '_GET'
         17        ISSET_ISEMPTY_DIM_OBJ                         0          ~23, 'data'
         18      > JMPZ                                                     ~24, ->47
   24    19    >   ECHO                                                     'Your+Search+Term+%3D%3D%3E+%3Cb%3E'
   25    20        INIT_FCALL                                               'print_r'
         21        INIT_FCALL                                               'htmlspecialchars'
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                         $25     
         24        SEND_VAR                                                 $25
         25        DO_ICALL                                                 
   26    26        ECHO                                                     '%3C%2Fb%3E%3Cbr%3E%3Cbr%3E%3Cbr%3E'
   27    27        INIT_FCALL                                               'substr'
         28        FETCH_R                      global              ~27     '_SERVER'
         29        FETCH_DIM_R                                      ~28     ~27, 'DOCUMENT_ROOT'
         30        SEND_VAL                                                 ~28
         31        SEND_VAL                                                 0
         32        SEND_VAL                                                 2
         33        DO_ICALL                                         $29     
         34        IS_IDENTICAL                                             $29, 'C%3A'
         35      > JMPZ                                                     ~30, ->42
   28    36    >   FETCH_R                      global              ~31     '_SERVER'
         37        FETCH_DIM_R                                      ~32     ~31, 'PHP_SELF'
         38        CONCAT                                           ~33     '%3Ca+href%3D%22http%3A%2F%2Flocalhost', ~32
         39        CONCAT                                           ~34     ~33, '%22%3EReset+Search%3C%2Fa%3E'
         40        ECHO                                                     ~34
         41      > JMP                                                      ->47
   29    42    >   FETCH_R                      global              ~35     '_SERVER'
         43        FETCH_DIM_R                                      ~36     ~35, 'PHP_SELF'
         44        CONCAT                                           ~37     '%3Ca+href%3D%22', ~36
         45        CONCAT                                           ~38     ~37, '%22%3EReset+Search%3C%2Fa%3E'
         46        ECHO                                                     ~38
   33    47    >   ECHO                                                     '%3Cbr%3E%0A++++%3Cbr%3E%0A++++%3Ccenter%3E%0A'
   35    48        CONCAT                                           ~39     '%3Cform+action%3D%22search.php%3F%26pages%3D10%26q%3D', !1
         49        CONCAT                                           ~40     ~39, '%26method%3D%22get%22%3E'
         50        CONCAT                                           ~41     ~40, '%0A'
   36    51        CONCAT                                           ~42     ~41, '%3Cinput+type%3D%22text%22+name%3D%22input-text%22+size%3D%2260%25%22%2F%3E'
         52        CONCAT                                           ~43     ~42, '%0A'
   37    53        CONCAT                                           ~44     ~43, '%3Cinput+type%3D%22submit%22+name%3D%22data%22+value%3D%22Web+Search%22%2F%3E'
         54        CONCAT                                           ~45     ~44, '%0A'
         55        CONCAT                                           ~46     ~45, '%3C%2Fform%3E'
         56        CONCAT                                           ~47     ~46, '%0A'
         57        ECHO                                                     ~47
   39    58        ECHO                                                     '%3C%2Fcenter%3E%0A++++%3Cpre%3E%0A++++%3Cbr%3E'
   42    59        FETCH_IS                                         ~48     '_GET'
         60        ISSET_ISEMPTY_DIM_OBJ                         0          ~48, 'data'
         61      > JMPZ                                                     ~49, ->187
   43    62    >   INIT_FCALL                                               'ini_set'
         63        SEND_VAL                                                 'max_execution_time'
         64        SEND_VAL                                                 0
         65        DO_ICALL                                                 
         66        INIT_FCALL                                               'set_time_limit'
         67        SEND_VAL                                                 0
         68        DO_ICALL                                                 
   44    69        FETCH_IS                                         ~52     '_GET'
         70        ISSET_ISEMPTY_DIM_OBJ                         0          ~52, 'q'
         71      > JMPZ                                                     ~53, ->76
   45    72    >   FETCH_R                      global              ~54     '_GET'
         73        FETCH_DIM_R                                      ~55     ~54, 'q'
         74        ASSIGN                                                   !2, ~55
         75      > JMP                                                      ->77
   46    76    >   ASSIGN                                                   !2, !1
   47    77    >   FETCH_IS                                         ~58     '_GET'
         78        ISSET_ISEMPTY_DIM_OBJ                         0          ~58, 'pages'
         79      > JMPZ                                                     ~59, ->84
   48    80    >   FETCH_R                      global              ~60     '_GET'
         81        FETCH_DIM_R                                      ~61     ~60, 'pages'
         82        ASSIGN                                                   !3, ~61
         83      > JMP                                                      ->85
   49    84    >   ASSIGN                                                   !3, 10
   50    85    >   FETCH_IS                                         ~64     '_GET'
         86        ISSET_ISEMPTY_DIM_OBJ                         0          ~64, 'start'
         87      > JMPZ                                                     ~65, ->92
   51    88    >   FETCH_R                      global              ~66     '_GET'
         89        FETCH_DIM_R                                      ~67     ~66, 'start'
         90        ASSIGN                                                   !4, ~67
         91      > JMP                                                      ->93
   52    92    >   ASSIGN                                                   !4, 0
   53    93    >   IS_SMALLER_OR_EQUAL                                      100, !3
         94      > JMPZ                                                     ~70, ->96
   54    95    >   ASSIGN                                                   !3, 100
   55    96    >   INIT_FCALL                                               'urlencode'
         97        SEND_VAR                                                 !2
         98        DO_ICALL                                         $72     
         99        CONCAT                                           ~73     'http%3A%2F%2Fwww.google.com%2Fsearch%3Fhl%3Den%26safe%3Doff%26filter%3D0%26q%3D', $72
        100        CONCAT                                           ~74     ~73, '%26start%3D'
        101        ASSIGN                                                   !5, ~74
   56   102        ASSIGN                                                   !6, 1
        103        ASSIGN                                                   !7, 0
   58   104        FETCH_CONSTANT                                   ~78     'CURLOPT_RETURNTRANSFER'
        105        INIT_ARRAY                                       ~79     <true>, ~78
   59   106        FETCH_CONSTANT                                   ~80     'CURLOPT_HEADER'
   58   107        ADD_ARRAY_ELEMENT                                ~79     <false>, ~80
   60   108        FETCH_CONSTANT                                   ~81     'CURLOPT_FOLLOWLOCATION'
   58   109        ADD_ARRAY_ELEMENT                                ~79     <true>, ~81
   61   110        FETCH_CONSTANT                                   ~82     'CURLOPT_ENCODING'
        111        ADD_ARRAY_ELEMENT                                ~79     '', ~82
   62   112        FETCH_CONSTANT                                   ~83     'CURLOPT_AUTOREFERER'
   58   113        ADD_ARRAY_ELEMENT                                ~79     <true>, ~83
   63   114        FETCH_CONSTANT                                   ~84     'CURLOPT_CONNECTTIMEOUT'
        115        ADD_ARRAY_ELEMENT                                ~79     120, ~84
   64   116        FETCH_CONSTANT                                   ~85     'CURLOPT_TIMEOUT'
        117        ADD_ARRAY_ELEMENT                                ~79     120, ~85
   65   118        FETCH_CONSTANT                                   ~86     'CURLOPT_MAXREDIRS'
        119        ADD_ARRAY_ELEMENT                                ~79     10, ~86
   66   120        FETCH_CONSTANT                                   ~87     'CURLOPT_COOKIEFILE'
        121        ADD_ARRAY_ELEMENT                                ~79     'cookie.txt', ~87
   67   122        FETCH_CONSTANT                                   ~88     'CURLOPT_COOKIEJAR'
        123        ADD_ARRAY_ELEMENT                                ~79     'cookie.txt', ~88
   68   124        FETCH_CONSTANT                                   ~89     'CURLOPT_USERAGENT'
        125        ADD_ARRAY_ELEMENT                                ~79     'Mozilla%2F5.0+%28Windows+NT+6.1%3B+WOW64%3B+rv%3A11.0%29+Gecko%2F20100101+Firefox%2F11.0', ~89
   69   126        FETCH_CONSTANT                                   ~90     'CURLOPT_REFERER'
        127        ADD_ARRAY_ELEMENT                                ~79     'http%3A%2F%2Fwww.google.com%2F', ~90
   57   128        ASSIGN                                                   !8, ~79
   70   129        ASSIGN                                                   !9, !4
        130      > JMP                                                      ->171
   71   131    >   INIT_FCALL_BY_NAME                                       'curl_init'
        132        CONCAT                                           ~93     !5, !9
        133        CONCAT                                           ~94     ~93, '0'
        134        SEND_VAL_EX                                              ~94
        135        DO_FCALL                                      0  $95     
        136        ASSIGN                                                   !10, $95
   72   137        INIT_FCALL_BY_NAME                                       'curl_setopt_array'
        138        SEND_VAR_EX                                              !10
        139        SEND_VAR_EX                                              !8
        140        DO_FCALL                                      0          
   73   141        ASSIGN                                                   !11, ''
   74   142        INIT_FCALL_BY_NAME                                       'curl_exec'
        143        SEND_VAR_EX                                              !10
        144        DO_FCALL                                      0  $99     
        145        ASSIGN_OP                                     8          !11, $99
   75   146        INIT_FCALL_BY_NAME                                       'curl_close'
        147        SEND_VAR_EX                                              !10
        148        DO_FCALL                                      0          
   76   149        ASSIGN                                                   !12, <array>
   77   150        INIT_FCALL                                               'preg_match_all'
        151        SEND_VAL                                                 '%2Fa+href%3D%22%28%5B%5E%22%5D%2B%29%22+class%3Dl.%2B%3F%3E.%2B%3F%3C%5C%2Fa%3E%2F'
        152        SEND_VAR                                                 !11
        153        SEND_REF                                                 !12
        154        DO_ICALL                                                 
   78   155        FETCH_DIM_R                                      ~104    !12, 1
        156      > FE_RESET_R                                       $105    ~104, ->167
        157    > > FE_FETCH_R                                               $105, !13, ->167
   79   158    >   ROPE_INIT                                     5  ~107    '+%3Ca+href%3D%27'
        159        ROPE_ADD                                      1  ~107    ~107, !13
        160        ROPE_ADD                                      2  ~107    ~107, '%27%3E'
        161        ROPE_ADD                                      3  ~107    ~107, !13
        162        ROPE_END                                      4  ~106    ~107, '%3C%2Fa%3E'
        163        CONCAT                                           ~110    ~106, '%0A'
        164        ECHO                                                     ~110
   80   165        PRE_INC                                                  !6
   78   166      > JMP                                                      ->157
        167    >   FE_FREE                                                  $105
   81   168        STRLEN                                           ~112    !11
        169        ASSIGN_OP                                     1          !7, ~112
   70   170        PRE_INC                                                  !9
        171    >   IS_SMALLER                                               !9, !3
        172      > JMPNZ                                                    ~115, ->131
   82   173    >   BEGIN_SILENCE                                    ~116    
        174        INIT_FCALL                                               'fclose'
        175        SEND_VAR                                                 !14
        176        DO_ICALL                                                 
        177        END_SILENCE                                              ~116
   83   178        SUB                                              ~118    !6, 1
        179        ASSIGN                                                   !15, ~118
   84   180        CONCAT                                           ~120    '%3Cbr%3E%3Cbr%3ENumber+of+results%3A+', !15
        181        CONCAT                                           ~121    ~120, '%0A'
        182        ECHO                                                     ~121
   85   183        DIV                                              ~122    !7, 1024
        184        CONCAT                                           ~123    'Total+KB+read%3A+', ~122
        185        CONCAT                                           ~124    ~123, '%0A'
        186        ECHO                                                     ~124
   87   187    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.46 ms | 1412 KiB | 35 Q