Created
June 5, 2014 08:49
-
-
Save dongyuwei/48e875887bdeb7df5905 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
URI = "http://google.com/complete/search?output=firefox&hl=en&q=" | |
def suggest(term): | |
text = urllib.urlopen(URI + urllib.quote(term)).read() | |
arr = eval(text) | |
return arr[1] | |
print suggest("python") |
#import <Foundation/Foundation.h>
//... see http://www.flaviodiez.com/2013/08/json-with-objective-c/
void testGoogleSuggestion(){
NSURL * url = [[NSURL alloc] initWithString:@"http://google.com/complete/search?output=firefox&hl=en&q=halle"];
// Prepare the request object
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
NSURLResponse *response;
NSError *error;
NSData* data = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
NSArray* object = [NSJSONSerialization
JSONObjectWithData:data
options:0
error:&error];
if(!error){
NSLog(@"%@",object[1]);
}else{
NSLog(@"error: %@",error);
}
}
wiktionary api need a custom User-Agent
header
http://nssug.baidu.com/su?x=1&prod=recon_dict&wd=halle&p=3&t=1402911230200 百度词典的速度非常快,20~30毫秒,对输入法而言在可接受范围内
call google suggestion jsonp api
$.jsonp({
url: 'http://google.com/complete/search?output=firefox&hl=en&q=halle',
callbackParameter: "callback",
success: function(data) {
console.log(data);
},
error: function() {
console.log(arguments);
}
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://google.com/complete/search?output=firefox&hl=en&q=halle