0%

英语单词笔记生成器

英语单词笔记生成器

必应爬虫

写一个文本文件i.txt, 使得它的每一行都是一个要查的单词或者词组。

然后把这段代码执行

import requests
from bs4 import BeautifulSoup

url = "https://cn.bing.com/dict/search?q=%s"
user_agent = "Mozilla/5.0 (Windows NT 10.0; WOW64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.5666.197 Safari/537.36"
# word = "supply"

def search(word):
    # try:
    response = requests.get(url % word, {"user-agent":user_agent})
    soup = BeautifulSoup(response.text, "html.parser")
    wordH1 = soup.find_all("h1")[1].text
    音标 = soup.find_all("div", class_="hd_prUS b_primtxt") + soup.find_all("div", class_="hd_pr b_primtxt")
    print(wordH1)
    for each in 音标:
        print(each.text)
    ul = soup.find_all("ul")[2]
    text = str(ul)
    soup1 = BeautifulSoup(text, "html.parser")
    meaningLi = soup1.find_all("li")
    for each in meaningLi:
        print(each.text)
    try:
        forms = soup.find("div", class_="hd_if").text
        print(forms)
    except:
        pass
    # using = soup.find("div", class_="wd_div").get_text(separator=" ").replace(" ,", ",")
    # print(using)
#     list1 = using.split(".")
#    for i in range(len(list1)):
#        list1.insert(i + 1, "  ")
#    using1 = ".".join(list1)
#    list2 = using1.split("+")
#    for i in range(len(list2)):
#        if i != 0:
#            list2[i] = list2[i][2:]
#    using2 = "+".join(list2)



        
        

        

    print()
#     for each in using.contents:
#         #print(each.text)
#         for eacheach in each.contents:
#             print(eacheach.text)
    # except:
    #     pass
    
    
if __name__ == "__main__":
    while True:
        word = input()
        if word != "":
            search(word)


使用命令

python3 1.py < i.txt > o.txt

然后就生成了一份英语的单词笔记

像这个

bound
美 [baʊnd]
英 [baʊnd]
n.跳跃;蹦跳
adj.一定会;很可能会;受(法律、义务或情况)约束(必须做某事)
v.跳跃着跑;形成…的边界(或界限)
网络惊世狂花;范围;限制
第三人称单数:bounds  现在分词:bounding  过去式:bounded  
同义词 反义词 adj. unlikely, free adj. certain, sure, obliged, forced v. border, border on, be contiguous to, touch, be adjacent to n. jump, leap, spring, bounce, hop

restore
美 [rɪˈstɔr]
英 [rɪˈstɔː(r)]
v.恢复;修复;恢复(某种情况或感受);使复原
网络还原;重建;归还
第三人称单数:restores  现在分词:restoring  过去式:restored  
搭配 同义词 v.+n. restore confidence, restore order, restore system, restore service, restore reputation v. reinstate, re-establish, reestablish, bring back, return

你也可以用这个脚本来便捷地查词,不加参数直接执行就好了