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

How can I use Google's image API to custom search for images and import them all?

share|improve this question
I used to just Import[] a search result page, but this is not possible anymore... Seems like v9 should have integration with google.images api – M.R. Mar 1 '13 at 21:33
This is a good question, why have people downvoted this? Scraping images is very common tool that people need. – M.R. Mar 1 '13 at 21:34
I don't know, this is an operation that most image processing people need. wolfram|alpha query and exampledata will not suffice most times... – user4364 Mar 1 '13 at 21:42
I think people are downvoting because you didn't try anything or post what you have done before submitting the question. – s0rce Mar 1 '13 at 22:06

2 Answers 2

up vote 27 down vote accepted

Using the (deprecated but easy) API documented here,

result = Import[
  "", "JSON"]

Import["url" /. ("results" /. ("responseData" /. result))[[1]]]

Mathematica graphics

If you hit the service too many times, it'll lock you out for a while.

Here's another example that gives the 24th-32nd results:

result = Import["", "JSON"];
share|improve this answer

Mathematica now supports a native connection to GoogleCustomSearch API.

To use image search you can do:

gs = ServiceConnect["GoogleCustomSearch"]
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
Can you give me some help on the "add a search engine" part? Specifically I'm stuck on the "sites to search" option, whereas I just want to search the web to get the results lik eyou have there – Jason B Nov 19 at 12:01
Yeah, it's a bit confusing. You can add there any website you want. As a test, just add for example. Give a name to your search engine and create it. After that go to "Modify your search engine" (Control Panel button) and once there, in the Sites to search section you'll see a select box with the option "Search only included sites". Change that option to "Search the entire web but emphasize included sites". With that you'll be able to search the entire web. Try that and let me know if you get better results. – xtian777x Nov 19 at 22:29

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.