Ai
3 Star 3 Fork 4

Gitee 极速下载/Uncaptcha

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/ecthros/uncaptcha
克隆/下载
thesaurus.py 790 Bytes
一键复制 编辑 原始数据 按行查看 历史
George Hughey 提交于 2017-10-27 12:28 +08:00 . Added ris
import requests
from bs4 import BeautifulSoup
def _get_soup_object(url, parser="html.parser"):
return BeautifulSoup(requests.get(url).text, parser)
#Takes in a word (string) and returns a list of synonyms
def getSynonyms(term, formatted=False, max=100):
if len(term.split()) > 1:
print("Error: A Term must be only a single word")
else:
try:
data = _get_soup_object("http://www.thesaurus.com/browse/{0}".format(term))
terms = data.select("div#filters-0")[0].findAll("li")
if len(terms) > max:
terms = terms[:max:]
li = []
for t in terms:
li.append(t.select("span.text")[0].getText())
if formatted:
return {term: li}
return li
except:
print("{0} has no Synonyms in the API".format(term))
#EXAMPLE
#for wrd in getSynonyms("car"):
# print wrd
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mirrors/Uncaptcha.git
git@gitee.com:mirrors/Uncaptcha.git
mirrors
Uncaptcha
Uncaptcha
master

搜索帮助