Fix getting search results from google broken because of markup changes

This commit is contained in:
Kovid Goyal 2021-04-02 10:43:33 +05:30
parent 4b0745052d
commit 3446f3b5d3
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -20,7 +20,7 @@ from calibre import browser as _browser, prints, random_user_agent
from calibre.utils.monotonic import monotonic from calibre.utils.monotonic import monotonic
from calibre.utils.random_ua import accept_header_for_ua from calibre.utils.random_ua import accept_header_for_ua
current_version = (1, 0, 6) current_version = (1, 0, 7)
minimum_calibre_version = (2, 80, 0) minimum_calibre_version = (2, 80, 0)
@ -233,13 +233,13 @@ def google_search(terms, site=None, br=None, log=prints, safe_search=False, dump
ans = [] ans = []
for div in root.xpath('//*[@id="search"]//*[@id="rso"]//*[@class="g"]'): for div in root.xpath('//*[@id="search"]//*[@id="rso"]//*[@class="g"]'):
try: try:
a = div.xpath('descendant::div[@class="rc"]//a[@href]')[0] a = div.xpath('descendant::a[@href]')[0]
except IndexError: except IndexError:
log('Ignoring div with no descendant') log('Ignoring div with no main result link')
continue continue
title = tostring(a) title = tostring(a)
try: try:
c = div.xpath('descendant::*[@role="menu"]//a[@class="fl"]')[0] c = div.xpath('descendant::*[@role="menuitem"]//a[@class="fl"]')[0]
except IndexError: except IndexError:
log('Ignoring {!r} as it has no cached page'.format(title)) log('Ignoring {!r} as it has no cached page'.format(title))
continue continue