Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to write a function that, starting from a string, returns the Google search hits on that string (the format and other stuff, I still have to decide).

I have looked around and have found nothing that works (the wsdl-thing for Google search referenced by the docs, with WebServices, is retired and returns 404).

Any hints, except scraping the result page by hand?

share|improve this question
Have a look at this answer. Presumably, Google expects you to switch to a newer API. – Leonid Shifrin Mar 2 '13 at 23:18
Take a look at this answer. You can use the same approach I show there, but that's a deprecated API as well. It works now, but it won't keep working for long. – Szabolcs Mar 2 '13 at 23:27

2 Answers 2

up vote 8 down vote accepted

After looking better into the comment by Szabolcs, I have chosen this path (which I did try for images, but it didn't cross my mind to use it for web):

result = Import[ "", "JSON"]

and then

"url" /. ("results" /. ("responseData" /. result))

to get the links to the pages. Or, to get the "preview" of the pages:

"content" /. ("results" /. ("responseData" /. result))

It works like a charm even if it is unsupported and bound to break at some point.

For reference:

share|improve this answer
I would advise setting the User agent string if you do this. – William Nov 24 '13 at 4:20
@mgm How could we launch a browser from mma with a given url programatically? The front-end can do this already for hyperlinks... – M.R. Apr 8 at 17:58

Mathematica now supports a native connection to GoogleCustomSearch API.

You can do for example

gs = ServiceConnect["GoogleCustomSearch"]
gs["Search", {"Query" -> "Jennifer Lawrence"}]

enter image description here

You can also use image search

gs["Search",{"Query"-> "Jennifer Lawrence","SearchType"-> "Image"}]

enter image description here

To use GoogleCustomSearch API you need an API Key and a Custom search engine ID.

To get the API Key you first have to go to and create a project if you don't have one yet. Once you have the project (asuming you are using the new console interface), click the Credentials menu at the left. There you'll see all your credentials. If don't have one, click the Add credentials and, for GoogleCustomSearch, you need the API key Browser key type.

For the Custom search engine ID, you have to go to and add a search engine. Once you create it, just click on that and you'll get a screen with a lot of options. There's a button there that says Search engine ID. Click it and you'll get the ID you need.

Here is the official Wolfram documentation for Google API.

You may also want to try the BingSearch service also available from Mathematica. The functionality is basically the same. Here is the official documentation for that.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.