-1

I am trying to fetch google trends page and the images that are shown are something in the code are actually like this

http://t2.gstatic.com/images?q=tbn:ANd9GcReZ5l9k236B8fRJQo2XuoaB30s-4wsUPZEYOWurvMjArDatu0vN_z2pHt4VAn_7Za_6xozCU3W

Since i need the real path to the image with its extension, is there any way to retrieve it?

Thank you.

Foon
  • 6,148
  • 11
  • 40
  • 42
sbiddo
  • 19
  • 3
  • Probably this is the "real" path. The images might be in a database. You should clarify your question to see what goal you have. Do you need to extract the images to a file system? Then you would need to put the images in some resource folder. You could infer the extension from the content-type response header from the url you posted. Then you would have to save them and replace the url with your own path... – Martin Mar 11 '15 at 11:55

2 Answers2

0

First off, this sounds like you're trying to screenscrape. Your life might be easier if you can review the API for google-trends and use that instead (but I don't know that api well enough to help you on that front; I did add the google-trend (in a to be peer reviewed edit) to your post to try to attract who do.)

Having said that, can you download the image and look at the content-type (assuming that image doesn't redirect to the underlying image in which case your problem should be solved.) You didn't specify what language you were using, so I'm going to assume you're using the right one :).

Example code (python, using requests library):

import requests
r = requests.get("http://gstatic.foo.com/blah/randomkeyboardtypingdetected/")
ctype = r.headers.get("content-type",None)
lookup = {"image/jpeg":"jpg","image/png":"png"} # add others as needed
if ctype and lookup.get(ctype,None):
   print lookup.get(ctype) 
else:
   print "Error, server didn't specify.
Foon
  • 6,148
  • 11
  • 40
  • 42
0

It is a real path, image is retrieved dynamically so path is not like regular one with file-name, extension etc.

You can check content type from response headers if you want to determine type of image.

Dharmang
  • 3,018
  • 35
  • 38