up vote 13 down vote favorite
1
share [g+] share [fb]

I have 3 or 4 keywords I want to send from my PHP page to Google and return one page as if I had gone on to Google's site and searched using "I'm feeling lucky."

Does anyone know how to supply the keywords to Google?

What is the format?

e.g.:

www.google.co.uk/lucky?keywords="the royal family"
link|improve this question
feedback

migrated from superuser.com Dec 26 '10 at 1:01

This question came from our site for computer enthusiasts and power users.

6 Answers

http://www.google.com/search?q=stackoverflow&btnI

Replace "stackoverflow" with your keywords.

link|improve this answer
Stripped to the bare minimum :) – Daniel Vassallo Feb 26 '10 at 15:37
I saw that "I am lucky button" has name=btnI, I wonder how did you know that it should be written to web site adress by appending to the end? – stckvrflw Feb 26 '10 at 15:47
Actually I inpected with Fiddler to see what URL was being requested upon clicking the "Feeling Lucky" button. Then I stripped all the obvious redundant parameters like language, source, etc from the URL, until I couldn't strip anymore. – Daniel Vassallo Feb 26 '10 at 15:52
thanks for explaining (: – stckvrflw Feb 26 '10 at 16:08
1  
Nice. That is the perfect answer! – marcusw Feb 26 '10 at 16:38
feedback

Like this:

http://www.google.com/search?hl=en&q={searchTerms}&btnI=I

I stands for Instant.

link|improve this answer
1  
Why doesn't the I stand for "I'm feeling lucky?" – Daniel Vassallo Feb 26 '10 at 15:40
1  
it does (it is the name of the button) put the browser removed everything after the ' – Hogan Feb 26 '10 at 16:17
The name btnI comes from Google. – SLaks Feb 26 '10 at 16:23
feedback

Add &btnI to the end of your query string

e.g. http://www.google.co.uk/search?q=the+royal+family&btnI

link|improve this answer
feedback

The URL you'd need is

`http://www.google.co.uk/search?q=SEARCHTERM&btnI=I'm+Feeling+Lucky`

where "SEARCHTERM" is the keywords.

link|improve this answer
feedback

Try this:

http://www.google.co.uk/search?q=the+royal+family&btnI=I

Replace "the+royal+family" with your url encoded search term.

link|improve this answer
feedback

Try this as an example:

<html>
  <body>
    <form action="http://www.google.com/search">
    <input type="hidden" name="btnI" checked="true" />
    <input type="text" name="q" value="" />
    <input type="Submit" value="Submit" />
  </body>
</html>

The important thing is to have an item named "btnI" with checked=true, and a value named "q" with your text.

link|improve this answer
4  
Hidden inputs don't have a checked attribute, and those inputs which do take the value of 'checked', not 'true' (even if browsers perform error recovery) – David Dorward Feb 26 '10 at 15:42
feedback

Your Answer

 
or
required, but never shown