| | |
JAvascript Search Eninge Script
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
~s.o.s~ is, again, completely correct ... and you do need some server side language since JavaScript has what is known as a sandbox which keeps it from doing cross-site scripting, as a security model.
The following is an unorthodox approach and i would recommend following ~s.o.s~'s advice and research the official API.
But all the server-side script you need is this (PHP) -- so long as Google doesn't change it's layout format.
googit.php
And to avoid the complexities of Ajax and iFrames this is the JavaScript to do the rest
Please forgive how lacking in style the above page is ... ;-)
I only worked this up for personal interest as a proof of concept
Ciao
The following is an unorthodox approach and i would recommend following ~s.o.s~'s advice and research the official API.
But all the server-side script you need is this (PHP) -- so long as Google doesn't change it's layout format.
googit.php
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<?php // Results <b>1</b> - <b>10</b> of about <b>1,420,000,000</b> -- CURRNET GOOGLE FORMAT $query = $_GET['q']; $result = file_get_contents( "http://www.google.com/search?q=$query" ); $found = preg_match( '#Results <b>\d+</b> - <b>\d+</b> of about <b>([\d,]+)</b>#', $result, $match ); if ( $found ) { $count = str_replace( ',', '', $match[1] ); } else { $count = "'false'"; } print "google( $count );"; ?>
And to avoid the complexities of Ajax and iFrames this is the JavaScript to do the rest
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!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> <style type="text/css"> body { padding: 60px; } </style> <script type="text/javascript"> window.onload = function () { document.getElementById('googit').onchange = function () { if ( script = document.getElementById('script') ) { script.parentNode.removeChild( script ); } var head = document.getElementsByTagName('head').item(0); var script = document.createElement('script'); script.setAttribute( 'id', 'script' ); script.setAttribute( 'type', 'text/javascript' ); script.setAttribute( 'src', 'googit.php?q=' + this.value ); head.insertBefore( script, head.firstChild ); document.getElementById('output').value = '... please wait ...'; }; }; function google ( result ) { var output = document.getElementById('output'); if ( result == 'false' ) { output.value = 'INVALID SEARCH'; } else { output.value = result; } } </script> </head> <body> <label for="googit">Get Google Count</label><br /> <label for="googit">Input: </label><input id="googit" type="text" /> <input type="submit" value="Touch Me" /><br /><br /> <label for="output">Result: </label><input id="output" type="text" /> </body> </html>
Please forgive how lacking in style the above page is ... ;-)
I only worked this up for personal interest as a proof of concept
Ciao
Last edited by langsor; Aug 15th, 2008 at 12:23 am.
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
Okay, my proof of concept fails for multiple word searches ... :-(
But I believe these two changes fix that
I'm done now ... thanks for bearing with me.
But I believe these two changes fix that
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
// replace javascript line (IE wants this) script.setAttribute( 'src', 'googit.php?q=' + this.value.replace( / /, '+' ) ); // add PHP line (FF wants this) $query = $_GET['q']; $query = str_replace( ' ', '+', $query );
I'm done now ... thanks for bearing with me.
Google don't take kindly to people running automated queries ( including scrapes ) without using their "official APIs", so you may find they block your server from communicating with the Google site if it makes alot of requests like this.
Which is hypocritic to say the least, since that's exactly how Google gathers its own information.
But anyway, certainly good stuff for a proof of concept.
Which is hypocritic to say the least, since that's exactly how Google gathers its own information.
But anyway, certainly good stuff for a proof of concept.
Plato forgot the nullahedron..
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
•
•
•
•
Google don't take kindly to people running automated queries ( including scrapes ) without using their "official APIs", so you may find they block your server from communicating with the Google site if it makes alot of requests like this.
Which is hypocritic to say the least, since that's exactly how Google gathers its own information.
But anyway, certainly good stuff for a proof of concept.
Anyone trying to do SEO and trying to keep up on google's rules will make your head spin with all the restrictions they impose (admittedly, most are for the good of all though)
Cheers
•
•
Join Date: Aug 2008
Posts: 1
Reputation:
Solved Threads: 0
Did you try looking at this ?
http://code.google.com/apis/ajaxsear...on/#The_Basics
http://code.google.com/apis/ajaxsear...on/#The_Basics
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: JDOMP problem
- Next Thread: Javascript: Open Url in Iframe using frameset
| Thread Tools | Search this Thread |
ajax ajaxexample ajaxjspservlets array browser bug captcha captchaformproblem cart checkbox child class close codes cookies createrange() cursor date debugger dependent disablefirebug dom dropdown editor element embed engine enter events explorer ext file firefox form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl maps marquee masterpage math matrixcaptcha media menu object onerror onmouseoutdivproblem onreadystatechange parent paypal pdf php position post programming progressbar prototype rated redirect runtime safari scale scriptlets scroll search security session shopping size software star stars synchronous toggle unicode variables web webservice wysiwyg \n






