From aa5420f47005e4e352ee869d709b66d230353493 Mon Sep 17 00:00:00 2001 From: Carson Gaspar Date: Tue, 20 Feb 2018 20:05:31 -0500 Subject: [PATCH] Fix for empty list error triggered by ASIN search --- src/calibre/ebooks/metadata/sources/search_engines.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/metadata/sources/search_engines.py b/src/calibre/ebooks/metadata/sources/search_engines.py index 87dd8d788a..be2d5eab6f 100644 --- a/src/calibre/ebooks/metadata/sources/search_engines.py +++ b/src/calibre/ebooks/metadata/sources/search_engines.py @@ -230,7 +230,11 @@ def google_search(terms, site=None, br=None, log=prints, safe_search=False, dump root = query(br, url, 'google', dump_raw, timeout=timeout) ans = [] for div in root.xpath('//*[@id="search"]//*[@id="rso"]//*[@class="g"]'): - a = div.xpath('descendant::h3[@class="r"]/a[@href]')[0] + try: + a = div.xpath('descendant::h3[@class="r"]/a[@href]')[0] + except IndexError: + log('Ignoring div with no descendant') + continue title = tostring(a) try: c = div.xpath('descendant::div[@class="s"]//a[@class="fl"]')[0]