Jump to content
GSForum - Segélyvonal

Google keresõ készítése


waxer

Recommended Posts

Kovács Gyula (MiniDisk)
<!-- Search Google -->
<center>
<form method="get" action="http://www.google.com/custom" target="_top">
<table bgcolor="#ffffff">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="http://www.google.com/">
<img src="http://www.google.com/logos/Logo_25wht.gif" border="0" alt="Google" align="middle"></img></a>
<input type="text" name="q" size="31" maxlength="255" value=""></input>
<input type="submit" name="sa" value="Keresés"></input>
<input type="hidden" name="client" value="pub-1436625392219764"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="ie" value="ISO-8859-2"></input>
<input type="hidden" name="oe" value="ISO-8859-2"></input>
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;"></input>
<input type="hidden" name="hl" value="hu"></input>
</td></tr></table>
</form>
</center>
<!-- Search Google -->

Link to comment
Share on other sites

Mezofi

Ezt kerestem a gépemen, mert egyszer már ajánlottad valakinek. De így legalább nem kell tovább keresnem. :)

Link to comment
Share on other sites

waxer

Köszi király !!

:)

Link to comment
Share on other sites

  • 4 months later...
SzoZo

Ez a keresõ ugyan mûködik, megfelel a HTML 4.x szabványainak, de én olyan kódot keresek amivel egyszerûen tudok Google keresõt betenni az XHTML szabványú weboldalra!

A legelsõ link tetszene, de az Chello-s!

 

Az alábbi kód szabványos, de nem fut! (Fõképpen az UW-n nem!)

 

<?php
############ PREFERENCES ############

$pref->text =      "No description.";        # Default text if no description is returned
$pref->title =      "Untitled";          # Default text if no title is returned
$pref->key =      "";            # your google API key, get yours at https://www.google.com/accounts/NewAccount
$pref->results =  "10";        # number of results (max 10)
$pref->start =      "auto";        # search number to be displayed first. "auto" will generate a navigation page
$pref->safe =      "true";        # toggles safeSearch on/off (false to turn if off)
$pref->filter =  "true";        # true if you wish google to filter out similar results


#####################################


# load the NuSOAP php library
require_once('nusoap.php');

# load the GET variable
$query = $_GET['q'];

# get the google results
$results = getResults($query);

# get document title
$title = getTitle($query);


#####################################
# FUNCTIONS START HERE

function getTitle($query)
    {
    #gets a different title if there has been a search query
    $title = !empty($_GET['q']) ? "Search results: ".$_GET['q'] : "Search";
    return $title;
    }

function getResults($query)
    {
    
    # get preferences
    global $pref;
    
    if ($pref->start == "auto") $start = empty($_GET['start']) ? 0 : $_GET['start'];
    else $start = $pref->start;
    
    # Set parameters
    $parameters = array(
 'key'=> $pref->key,
 'q' => $query,
 'start' => $start,
 'maxResults' => $pref->results,
 'filter' => $pref->filter,
 'restrict' => '',
 'safeSearch' => $pref->safe,
 'lr' => '',
 'ie' => 'latin',
 'oe' => 'latin'
    );

    # Create a new SOAP client, feeding it GoogleSearch.wsdl on Google's site
    $soapclient = new soapclient('http://api.google.com/GoogleSearch.wsdl', 'wsdl');

    # query Google
    $results = $soapclient->call('doGoogleSearch',$parameters);

    # Results?
    $trans = get_html_translation_table(HTML_ENTITIES); # get html translations
    $amount = $results['estimatedTotalResultsCount'];
    if ( is_array($results['resultElements']) ) {
 $html = "<p class=\"results\">Results <strong>".($start+1)." - ".($start+$pref->results)."</strong> of about <strong>$amount</strong> for <strong>$query</strong></p>\n";
 $html.= "<dl>\n";
 foreach ( $results['resultElements'] as $result ) {
 
     $snippet = $result['snippet'] ? $result['snippet'] : $pref->text;
     $snippet = preg_replace("/<b>([^<]+)<\/b>/","<strong>\\1</strong>",strip_tags($snippet,"<b>"));
     
     $url = preg_replace("/&/","&",$result['URL']);
     
     $title = $result['title'] ? $result['title'] : $pref->title;
     $title = preg_replace("/<b>([^<]+)<\/b>/","<strong>\\1</strong>",strip_tags($title,"<b>"));
     
     $html.= "\t<dt><a href=\"$url\">$title</a></dt>\n";
     $html.= "\t<dd>$snippet</dd>\n";
     $html.= "\t<dd class=\"url\">".preg_replace("/http\:\/\//","",$url)." - ".$result['cachedSize']."</dd>\n";
     
 }
 $html.= "</dl>\n";
    }
    
    # else no results
    elseif (!empty($query)) $html = "<p>Your search for <q>$query</q> returned no results.</p>";
    
    # This will present a navigation, if start is set to auto
    if ($pref->start == "auto" && !empty($query) && $amount != 0)
 {
 $disp = $_GET['start'];
 if(!empty($disp) && $disp > 1)
     {
     $pag = $disp>($pref->results-1) ? $disp - $pref->results : 0;
     $prev = "<strong><a href=\"".$_SERVER['PHP_SELF']."?q=$query&start=$pag\">Previous</a></strong> ";
     }
 if ($amount - $disp > $pref->results)
     {
     $pag = $disp+$pref->results;
     $next = "<strong><a href=\"".$_SERVER['PHP_SELF']."?q=$query&start=$pag\">Next</a></strong> ";
     }
 if ($amount > $pref->results)
     {
     $html.="<p class=\"nav\">Result page: $prev";
     if ($disp>0)
   {
   $be_disp = $disp >=($pref->results*10) ? ($disp/$pref->results)-($pref->results-1) : 1;
   for ($x=$be_disp;$x<(($disp/$pref->results)+1);$x++)
       {
       $html.="<a href=\"".$_SERVER['PHP_SELF']."?q=$query&start=".(($x-1)*$pref->results)."\">$x</a> ";
       }
   }
     $to_disp = floor($amount/$pref->results) > $pref->results ? ($disp/$pref->results)+11 : (floor($amount/$pref->results)+1);
     for($x=(($disp/$pref->results)+1); $x<$to_disp; $x++)
   {
   $html.= ($x-1)*$pref->results == $disp ? "<span>$x</span> " : "<a href=\"".$_SERVER['PHP_SELF']."?q=$query&start=".(($x-1)*$pref->results)."\">$x</a> ";
   }
     $html.=$next."</p>\n";
     }
 }

    return $html;
    }
    
### END PHP ###
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title><?php echo $title; ?></title>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"></meta>
<style type="text/css" media="all">

/* reflects somewhat googles default style. Modify as you wish. */

* { margin: 0; padding: 0; }
body { font: 0.85em/1.15em arial, sans-serif; margin: 3em; }
a:link { color: #00c }
a:visited { color: #551a8b; }
a:active { color: #f00; }
dt { font-weight: normal; font-size: 1.2em; margin-top: 1.2em;}
dd.url { color: #008000; }
form { margin-bottom: 1.5em; padding-bottom: 1.5em; border-bottom: 1px solid #aaa; }
p.nav { margin-top: 1.5em; padding-top: 1.5em; border-top: 1px solid #aaa;}
p.nav a:link, p.nav a:visited, p.nav a:active { color: #000; margin-right: 0.3em; }
p.nav strong { font-size: 1.3em; }
p.nav strong a:link, p.nav strong a:visited, p.nav strong a:active { color: #00c; }
p.nav span { color:#a90a08; font-weight: bold; margin-right: 0.3em; }

</style>
</head>
<body>
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><label for="q">Search:</label> <input type="text" value="<?php echo $_GET['q']; ?>" name="q" id="q" /> <input type="submit" value="search" /></p>
</form>
<?php echo $results; ?>
</body>
</html>

Link to comment
Share on other sites

Mezofi

Nekem ez van az uw-n és mûködik.

 

<form method="get" action="http://www.google.com/custom" target="_top">
<table bgcolor="#cccccc">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="http://www.google.com/">
<img src="http://www.google.com/logos/Logo_25gry.gif" border="0" alt="Google" align="middle"></img></a>
<input type="text" name="q" size="31" maxlength="255" value=""></input>
<input type="submit" name="sa" value="Keresés"></input>
<input type="hidden" name="client" value="pub-6391460990760221"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="ie" value="ISO-8859-2"></input>
<input type="hidden" name="oe" value="ISO-8859-2"></input>
<input type="hidden" name="cof" value="GALT:#663300;GL:1;DIV:#333333;VLC:663300;AH:center;BGC:FFCC00;LBGC:333333;ALC:000000;LC:000000;T:333300;GFNT:000000;GIMP:000000;FORID:1;"></input>
<input type="hidden" name="hl" value="hu"></input>
</td></tr></table>
</form>

De ha ellátogatsz az oldalamra, és a baloldali Google AdSense reklámra kattintasz, akkor eljutsz a Google oldalára ahol reggelsz és utána tudsz bannert igényelni amiért fizetnek, plussz keresõ részeket is letölthetsz.

:)

Link to comment
Share on other sites

SzoZo

 <!--Google kereso kezd-->
           <form method="get" action="http://www.google.co.hu/search">
             <table width="400">

               <tr> 
                 <td align="center" width="400"> <input type="text" name="q" size="40" maxlength="100" value="" /> 
                   <input type="submit" name="btnG" value="Google Keresõ" /> 
                   <input type="hidden" name="domains" value="www.szozo.atw.hu" /> 
                   <br />
                   <input name="sitesearch" type="radio" value="" checked="checked" /> 
                   www <input type="radio" name="sitesearch" value="http://szozo.atw.hu" /> 
                   SzoZo <br /> </td>
               </tr>
             </table>

           </form>
<!--Google kereso vege-->

Idõközben megcsináltam. :upsz:

Ez is megfelel az XHTML1.1-nek, és nem sárga, egyszerûen csak be kell illeszteni.

Link to comment
Share on other sites

  • 6 months later...
viktro

Hi, bocs hogy leporolom a topikot, de elakadtam.

 

Szal SOAP-ot használva akarnék gogle kérésekre adott válaszokat feldolgozni, de bármit csinálok a kérésben lévõ ékezetek mintha ott sem lennének. Ugyanazok a találatok jönnek ki "házikó" szóra mint a "hzik" szóra. Ahogy turkáltam a kódban, elmenni még tuti elmennek az ékezetek.

 

ez van most:

 

$parameters = array(

"key" => $key,

"q" => $Query,

"start" => $start,

"maxResults" => 5,

"filter" => true,

"restrict" => "",

"safeSearch" => false,

"lr" => "lang_hu",

"ie" => "",

"oe" => ""

);

 

$soapclient = new soapclient("http://api.google.com/search/beta2"); // [1]

$result = $soapclient->call("doGoogleSearch", $parameters, "urn:GoogleSearch");

 

 

de a paramétereknél az ie és oe tagoknak adtam már "ISO-8859-2" illetve "latin" értékeket is, de a helyzet változatlan. Tipp, tanács, ötlet?

Link to comment
Share on other sites

zsoltchelsea

Nagyon PHP-nak tûnik, inkább ott kopogtass.

Link to comment
Share on other sites

SzoZo

Lehetséges, hogy rossz karakterkódolást használsz? Ugyanis gyakran kell a betûk helyett kódot használni. Nyilván egy felhasználótól nem várható el a kódok megtanulása, ezért nézd meg elõtte a HEAD tagok között lévõ meta tagot és a charset értékét. Ha a charset windows-1250, vagy más írd át UTF-8 -ra!

Link to comment
Share on other sites

zsoltchelsea

ÁÁÁÁÁÁÁÁÁ. Tényleg. Azt hiszem jöhet elõ a könyv. Pedig régen tudtam.:lol::lol:

 

Annyit tennék még hozzá utólag, hogy teljes kódot próbálj meg berakni, és használható a kód beszúrása rész is. Átláthatóbb lesz tõle.

Link to comment
Share on other sites

  • 5 months later...
praad

Sziasztok!

 

Nézzétek már meg légyszi:

 

http://www.pranczek.hu/Gapi/gapi.html

 

Az a gond, hogy csak 8db találatot ad vissza! Mit lehetne tenni ezzel, mert nekem legalább 20 találat kéne az oldalon!

Nincs ötletetek?

A Googlenak már nincs meg a Soapos keresõje, amivel meg lehetne ezt oldani!

Csak ez az Ajaxos kaki! És sehol nem találom a doksijába, hogy hogyan lehetne ezt megoldani.

Remélem tudtok segíteni!

 

Köszi!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...