Skip to content
Permalink
Browse files

Fix Google Images failing for some countries

  • Loading branch information...
desbma committed Apr 11, 2016
1 parent faff5ff commit 36de51210a870237fecab6b5e0e3881155ed90d5
Showing with 12 additions and 6 deletions.
  1. +12 −6 sacad/sources/google_images.py
@@ -53,14 +53,17 @@ def parseResults(self, api_data):
results_selector = lxml.cssselect.CSSSelector("#search #rg_s .rg_di")
for rank, result in enumerate(results_selector(html), 1):
# extract url
google_url = result.find("a").get("href")
query = urllib.parse.urlsplit(google_url).query
query = urllib.parse.parse_qs(query)
img_url = query["imgurl"][0]
# extract format
metadata_div = result.find("div")
metadata_json = lxml.etree.tostring(metadata_div, encoding="unicode", method="text")
metadata_json = json.loads(metadata_json)
google_url = result.find("a").get("href")
if google_url is None:
img_url = metadata_json["ou"]
else:
query = urllib.parse.urlsplit(google_url).query
query = urllib.parse.parse_qs(query)
img_url = query["imgurl"][0]
# extract format
check_metadata = CoverImageMetadata.NONE
format = metadata_json["ity"].lower()
try:
@@ -70,7 +73,10 @@ def parseResults(self, api_data):
format = None
check_metadata = CoverImageMetadata.FORMAT
# extract size
size = tuple(map(int, (query["w"][0], query["h"][0])))
if google_url is None:
size = metadata_json["ow"], metadata_json["oh"]
else:
size = tuple(map(int, (query["w"][0], query["h"][0])))
# extract thumbnail url
thumbnail_url = metadata_json["tu"]
# result

0 comments on commit 36de512

Please sign in to comment.
You can’t perform that action at this time.