 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Madroaster
Joined: 25 Feb 2010 Posts: 23
|
Posted: Thu Feb 25, 2010 10:18 pm Post subject: Google search with quotes doesn't work, no error code |
|
|
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 |
|
 |
Carcophan
Joined: 24 Dec 2008 Posts: 1308 Location: :noitacoL
|
Posted: Thu Feb 25, 2010 10:21 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
Carcophan
Joined: 24 Dec 2008 Posts: 1308 Location: :noitacoL
|
|
| Back to top |
|
 |
garry
Joined: 19 Apr 2005 Posts: 2214 Location: switzerland
|
Posted: Thu Feb 25, 2010 11:20 pm Post subject: |
|
|
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 |
|
 |
Madroaster
Joined: 25 Feb 2010 Posts: 23
|
Posted: Thu Feb 25, 2010 11:33 pm Post subject: |
|
|
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 |
|
 |
garry
Joined: 19 Apr 2005 Posts: 2214 Location: switzerland
|
Posted: Fri Feb 26, 2010 12:04 am Post subject: |
|
|
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 |
|
 |
Madroaster
Joined: 25 Feb 2010 Posts: 23
|
Posted: Fri Feb 26, 2010 1:26 am Post subject: |
|
|
| garry wrote: | works for me also when I added + instead space
|
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 |
|
 |
garry
Joined: 19 Apr 2005 Posts: 2214 Location: switzerland
|
Posted: Fri Feb 26, 2010 5:49 am Post subject: |
|
|
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 |
|
 |
Madroaster
Joined: 25 Feb 2010 Posts: 23
|
Posted: Fri Feb 26, 2010 3:03 pm Post subject: |
|
|
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 |
|
 |
garry
Joined: 19 Apr 2005 Posts: 2214 Location: switzerland
|
Posted: Fri Feb 26, 2010 4:58 pm Post subject: |
|
|
(corrected above)
sorry, not tested all , hope it works now
tested
"Grace Chang" "Ge Lan"
-and-
Dumaguete |
|
| Back to top |
|
 |
Madroaster
Joined: 25 Feb 2010 Posts: 23
|
Posted: Fri Feb 26, 2010 6:03 pm Post subject: |
|
|
| It works perfectly now. Thanks very much...no apology necessary. You've been a great help! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|