Fix bug that can not query word like 'Saudi Arabia' by longman and oxford learning
This commit is contained in:
parent
9c4771fdf9
commit
bb487e1259
@ -4,6 +4,7 @@ import os
|
||||
import re
|
||||
from bs4 import Tag
|
||||
from ..base import *
|
||||
from ...utils.misc import format_multi_query_word
|
||||
|
||||
|
||||
longman_download_mp3 = True
|
||||
@ -17,7 +18,7 @@ class Longman(WebService):
|
||||
super(Longman, self).__init__()
|
||||
|
||||
def _get_from_api(self):
|
||||
url = 'https://www.ldoceonline.com/dictionary/{}'.format(self.quote_word)
|
||||
url = 'https://www.ldoceonline.com/dictionary/{}'.format(format_multi_query_word(self.quote_word))
|
||||
data = self.get_response(url)
|
||||
soup = parse_html(data)
|
||||
# Top Container
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
from bs4 import Tag
|
||||
from ..base import *
|
||||
from ...utils.misc import format_multi_query_word
|
||||
|
||||
#filterwarnings('ignore')
|
||||
|
||||
@ -22,7 +23,7 @@ class OxfordLearning(WebService):
|
||||
:param word:
|
||||
:rtype: WebWord
|
||||
"""
|
||||
qry_url = u'https://www.oxfordlearnersdictionaries.com/definition/english/{}'.format(word)
|
||||
qry_url = u'https://www.oxfordlearnersdictionaries.com/definition/english/{}'.format(format_multi_query_word(word))
|
||||
|
||||
retried = 10
|
||||
while retried:
|
||||
|
||||
@ -60,6 +60,16 @@ def get_icon(filename):
|
||||
return QIcon(path)
|
||||
|
||||
|
||||
# Some query words like 'Saudi Arabia' is comprised by two or more words that split by '%20'(space),
|
||||
# it is an invalid query format. (Validated Dictionary: Longman, oxford learning)
|
||||
def format_multi_query_word(words: str):
|
||||
_space = '%20'
|
||||
if words is None or _space not in words:
|
||||
return words
|
||||
|
||||
return words.lower().replace(_space, '-')
|
||||
|
||||
|
||||
class MapDict(dict):
|
||||
"""
|
||||
Example:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user