AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Google search with quotes doesn't work, no error code

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Madroaster



Joined: 25 Feb 2010
Posts: 23

PostPosted: Thu Feb 25, 2010 10:18 pm    Post subject: Google search with quotes doesn't work, no error code Reply with quote

Hi All,

I have a general script with a line to send search requests to Google. The code is:

Code:
; Google Search Box
^Delete::
InputBox, varInput, Google Search,
,, 540, 180,,,, 90,
if ErrorLevel = 0 ; OK or Enter
{
   if varInput <> ; if input not empty
            Run, http://www.google.ca/search?q=%varInput% ; execute the command
      }
Return


When I send a search request including quotation marks with more than one word, the scripts breaks--nothing happens, and there is no error code.

So, sending (without brackets) <test test test> works fine. Sending <test test "test"> works fine. But sending <test "test test"> does nothing at all. Can anyone explain how I can fix this?

Thanks!
Back to top
View user's profile Send private message
Carcophan



Joined: 24 Dec 2008
Posts: 1308
Location: :noitacoL

PostPosted: Thu Feb 25, 2010 10:21 pm    Post subject: Reply with quote

Spaces are treated different in urls. They invlove %'s and stuff.

I don't know exactly off the top of my head, but its lke %a20% or something, you have probably seen them 1000 times and never even noticed. Google it Smile
Back to top
View user's profile Send private message
Carcophan



Joined: 24 Dec 2008
Posts: 1308
Location: :noitacoL

PostPosted: Thu Feb 25, 2010 10:21 pm    Post subject: Reply with quote

Carcophan wrote:
Google it Smile


http://www.webmasterworld.com/forum92/2045.htm
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 2214
Location: switzerland

PostPosted: Thu Feb 25, 2010 11:20 pm    Post subject: Reply with quote

an example
Code:
LAC=Grace Chang
transform,S,chr,32    ;space
transform,P,chr,37    ;procent
stringreplace,LAC,LAC,%S%,+,all
LAC=%P%22%LAC%%P%22
URL1=http://www.google.com/search?complete=1&hl=en&num=100&q=%LAC%
run,%URL1%
return
Back to top
View user's profile Send private message
Madroaster



Joined: 25 Feb 2010
Posts: 23

PostPosted: Thu Feb 25, 2010 11:33 pm    Post subject: Reply with quote

Thanks, that explains the problem.

I'm not a programmer, so I don't know how to write the code that replaces spaces between quotation marks in my query with %20. Can someone please show me how that's done?
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 2214
Location: switzerland

PostPosted: Fri Feb 26, 2010 12:04 am    Post subject: Reply with quote

works for me also when I added + instead space
Code:
transform,S,chr,32    ;space
transform,P,chr,37    ;procent

InputBox, varInput, Google Search,,, 540, 180,,,, 90,
;stringreplace,varInput,varInput,%S%,+,all   ;replace space with +
stringreplace,varInput,varInput,%S%,`%20,all  ;replace space with `%20
varInput=%P%22%varInput%%P%22   ;add "  "   or  `%22
URL1=http://www.google.com/search?complete=1&hl=en&num=100&q=%varInput%

if ErrorLevel = 0 ; OK or Enter
     {
     if varInput <> ; if input not empty
            {
            Run,%URL1%
            }
     }
Return
Back to top
View user's profile Send private message
Madroaster



Joined: 25 Feb 2010
Posts: 23

PostPosted: Fri Feb 26, 2010 1:26 am    Post subject: Reply with quote

garry wrote:
works for me also when I added + instead space
Code:
(See code above)


Thanks for this. I've tried it and it does replace the spaces with the %20, but it has a bug.

If I search for (minus brackets) < test "search one" >, it searches Google for < "test search one" >. Can you fix this by any chance?
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 2214
Location: switzerland

PostPosted: Fri Feb 26, 2010 5:49 am    Post subject: Reply with quote

yes , this replace your input " with `%22
Code:

transform,S,chr,32    ;space
InputBox, LAC1, Google Search,,, 540, 180,,,, 90,
stringreplace,LAC1,LAC1,%S%,`%20,all    ;-- replace space
stringreplace,LAC1,LAC1,`",`%22,all     ;-- replace bracket
URL1=http://www.google.com/search?complete=1&hl=en&num=100&q=%LAC1%
if LAC1<>
 Run,%URL1%
Return


EDIT corrected


Last edited by garry on Fri Feb 26, 2010 4:55 pm; edited 1 time in total
Back to top
View user's profile Send private message
Madroaster



Joined: 25 Feb 2010
Posts: 23

PostPosted: Fri Feb 26, 2010 3:03 pm    Post subject: Reply with quote

That has solved the quotation marks issue, but now there is this problem:

Searching for < test "test test" > works correctly, but searching for < test > does nothing at all. It seems the query is only recognized when there are quotation marks.
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 2214
Location: switzerland

PostPosted: Fri Feb 26, 2010 4:58 pm    Post subject: Reply with quote

(corrected above)
sorry, not tested all , hope it works now
tested
"Grace Chang" "Ge Lan"
-and-
Dumaguete
Back to top
View user's profile Send private message
Madroaster



Joined: 25 Feb 2010
Posts: 23

PostPosted: Fri Feb 26, 2010 6:03 pm    Post subject: Reply with quote

It works perfectly now. Thanks very much...no apology necessary. You've been a great help!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group