PDA

View Full Version : سوال: نمایش لینک های نتایج جست وجوی گوگل در php



arlvl4n.z3r0
پنج شنبه 19 اردیبهشت 1392, 07:09 صبح
سلام دوستان.
من میخوام توی یک فایل php بر اساس یک متن جست و جو که توی یک متغیر قرار دادم لینک نتایج جست و جو رو برام به صورت متن بنویسه.
اگه ممکنه راهنمایی کنید.

nsco_nsco
پنج شنبه 19 اردیبهشت 1392, 07:34 صبح
سلام کامل توضیح بده منظورت جستجو گوگل یا یک متن تو یک صفحه ؟

sh.n.n786
پنج شنبه 19 اردیبهشت 1392, 08:32 صبح
درود فکر کنم منظور شما این بود با این کد شما سورس گوگل رو درمیارید بعد باید با Regex یا DOM یا ... قسمت هایی که می خواهید رو استخراج کنید


function GoogleReader($title,$ssl,$page){
// google algoritms //
$googlessl = array(
'w5GOUZ9bE1fexAA6-OPoBl' , 'e9JSUx9jE9fetDa6-00oAF' ,
'f9PSUx9LE5fetBa9-BaSwP' , 'AljSgp9jg9KoGDa6-12DPP' ,
'MakkUFoGh5fK5IDf-jMotF' , 'pjkd041239ShiDa6-90F5J' ,
'Pg5Gdf66EbOPOGa1-GaS9f' , 'o5jSgp9jg0Hovva6-19gPg'
);
// curl headers //
$tit = 'allintitle:'.urlencode($title);
$contentType = 'text/xml';
$method = 'POST';
$auth = '';
$header1 = 'Authentication-API-Key: ' . rand(1000,999);
$charset= 'utf-8';
//$url = 'http://www.google.com/search?output=search&sclient=psy-ab&q='.urlencode($tit).'&btnK=&start='.$page;
// Dynamic url //
$url = "http://www.google.com/search?q={$tit}&bav=on.2,or.r_qf.&bvm=
bv.".rand(10000000,99999999).",d.Yms&biw=".rand(1000,1144)."&bih=".rand(600,900)."&um=1&hl=en&ie=UTF-8&
sa=N&tab=iw&ei=".$googlessl[$ssl]."&start=" . $page;
curl_init($ch);
curl_setopt($ch , CURLOPT_HEADER , 0);
curl_setopt($ch , CURLOPT_TIMEOUT , 50);
curl_setopt($ch , CURLOPT_SSLVERSION,3);
curl_setopt($ch , CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch , CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch , CURLINFO_HEADER_OUT, true);
curl_setopt($ch , CURLOPT_HTTPHEADER , Array('Content-type: ' .$contentType . '; charset=' . $charset,$header1));
curl_setopt($ch , CURLOPT_USERAGENT , "Mozilla/5.0 (Windows NT 5.1; rv:20.0) Gecko/20100101 Firefox/20.0");
curl_setopt($ch , CURLOPT_PORT , "80");
curl_setopt($ch , CURLOPT_INTERFACE , "127.0.0.1");
curl_setopt($ch , CURLOPT_FOLLOWLOCATION , 1);
curl_setopt($ch , CURLOPT_URL , $url);
$res = curl_exec($ch);
curl_close($ch);

قسمت اول $title : شما متن جستجو رو قرار میدید
قسمت دوم $ssl : این قسمت به صورت دندوم باید وارد بشه به این شکل rand(0,7);
قسمت سوم $page : صفحه گوگل

موفق باشید