获取单词正式进入英语词典的日期

2 投票
1 回答
671 浏览
提问于 2025-04-18 04:34

我想追踪不同单词进入英语词典(比如牛津词典、梅里亚姆-韦伯斯特词典等)的日期。

我希望能找到一个API,这样如果我发送“selfie”这个词,就能得到“2013”作为回复的一部分,但我觉得这种数据并不常见,甚至不容易获取。

我查过:

但是这两个地方似乎都没有提供这个数据的访问。

我正在使用python,也在pypi.python.org上查找过,但还没有找到能解决这个问题的模块。

看起来我可能得手动收集我想要的数据,但在这样做之前,我想看看有没有人知道更好的方法。

1 个回答

0

这是一个简单的脚本,用来获取单词。如果一个单词有多个意思,它只会选择其中一个。

import re
import urllib2

# Import Custom libraries
from BeautifulSoup import BeautifulSoup

def render_oxford_uri(term):
    '''
    Render the appropriate Oxford request uri
    '''
    base_url = "http://www.oxforddictionaries.com/definition/english/"
    url = base_url + ("%s?q=%s" % (re.sub("\s+", "-", term), re.sub("\s+", "+", term)))
    return url

def get_words(*args):
    '''
    Oxford dictionary word scraper
    '''
    ret_list = []
    for term in args:
        request_uri = render_oxford_uri(term)
        request = urllib2.Request(request_uri, None, {})

        try:
            response = urllib2.urlopen(request)
            the_page = response.read()
        except Exception:
            the_page = ""

        if the_page:
            pool   = BeautifulSoup(the_page)
            result = pool.find("div", attrs={"class" : "entryPageContent"})

            if result:
                term        = result.find("h2"  , attrs={"class" : "pageTitle"})
                speech_part = result.find("span", attrs={"class" : "partOfSpeech"})
                definition  = result.find("span", attrs={"class" : "definition"})
                date        = result.find("span", attrs={"class" : "date"})

                cur_dict = \
                {
                    "Term"           : term.text,
                    "Part of Speech" : speech_part.text,
                    "Definition"     : definition.text,
                    "Date"           : date.text,
                }
                ret_list += [cur_dict]

    return ret_list

if __name__ == "__main__":
    print get_words("selfie", "vapid")

撰写回答