how to create a link to google search and pass a keyword
Hey I'm trying to creare a link that passes the link's text directly to a google search. For example my link is "fishing tips", when it is pressed a new page shows up with google search results for "fishing tips". I trie开发者_C百科d this, but it won't work. Thx for your time!
link_to "fishing tips", "http://www.google.com/search", :query => "fishing tips", :target => "_blank", :method => :get
Make your request as "http://www.google.com/search?q=fishing+tips" instead of giving the query separately.
so it goes like
http://www.google.com/search?ie=UTF-8&q={YOUR_QUERY_HERE}
I couldn't get this to work in Google Sheets, however I did find a solution.
Specifically I needed to take a string from a cell in Sheets and embed it in a link that launched a Google search on that string.
The link code above is correct, in my case as follows:
="https://www.google.com/search?q="&A2
where A2
is the field containing the query string.
However the key finding was that the query string has to be parsed of blank spaces. Spaces must be replaced with %20
in order to function as a clickable link in Google Sheets.
The resulting formula that works is:
="https://www.google.com/search?q="&SUBSTITUTE(A2," ","%20")
Got it. Thats the way I needed it. Works fine
link_to google_query, "http://www.google.de/search?q=#{google_query}", :target => "_blank"
精彩评论