[fix] fetch google's supported languages

This commit is contained in:
Marc Abonce Seguin 2019-01-06 21:31:45 -06:00
parent 51111c2594
commit 0169b63e84
3 changed files with 27218 additions and 26970 deletions

File diff suppressed because it is too large Load diff

View file

@ -381,10 +381,10 @@ def attributes_to_html(attributes):
def _fetch_supported_languages(resp): def _fetch_supported_languages(resp):
supported_languages = {} supported_languages = {}
dom = html.fromstring(resp.text) dom = html.fromstring(resp.text)
options = dom.xpath('//table//td/font/label/span') options = dom.xpath('//*[@id="langSec"]//input[@name="lr"]')
for option in options: for option in options:
code = option.xpath('./@id')[0][1:] code = option.xpath('./@value')[0].split('_')[-1]
name = option.text.title() name = option.xpath('./@data-name')[0].title()
supported_languages[code] = {"name": name} supported_languages[code] = {"name": name}
return supported_languages return supported_languages

View file

@ -205,29 +205,13 @@ class TestGoogleEngine(SearxTestCase):
html = u""" html = u"""
<html> <html>
<body> <body>
<table> <div id="langSec">
<tbody> <div>
<tr> <input name="lr" data-name="english" value="lang_en" />
<td> <input name="lr" data-name="中文 (简体)" value="lang_zh-CN" />
<font> <input name="lr" data-name="中文 (繁體)" value="lang_zh-TW" />
<label> </div>
<span id="ten">English</span> </div>
</label>
</font>
</td>
<td>
<font>
<label>
<span id="tzh-CN">中文 (简体)</span>
</label>
<label>
<span id="tzh-TW">中文 (繁體)</span>
</label>
</font>
</td>
</tr>
</tbody>
</table>
</body> </body>
</html> </html>
""" """