Say that I have a word in Spanish, 'contador', for which I want to obtain a finite set of synonyms '['contable','tesorero','medidor',...]'.
I am aware that I can obtain synonyms from Wordnet Synsets in Python, but only for words in English.
My question is: how can I generate the desired list of synonyms with Python?
答案 0 :(得分:1)
You can use webscraping to find a list of synonyms from an online dictionary:
import urllib
from bs4 import BeautifulSoup as soup
import re
data = str(urllib.urlopen('https://educalingo.com/en/dic-es/{}'.format('contador')).read())
final_results = re.findall('\w+', [i.text for i in soup(data, 'lxml').find_all('div', {"class":'contenido_sinonimos_antonimos'})][0])
Output:
[u'cajero', u'contable', u'cuentarrevoluciones', u'electr', u'metro', u'interventor', u'medidor', u'tax', u'metro', u'tesorero', u'volt', u'metro']