import re
from time import sleep
from bs4 import BeautifulSoup
import requests
import json
def get_words():
dic = {}
r = requests.get("https://www.yjbys.com/edu/cet4/401193.html")
if r.status_code == 200:
soup = BeautifulSoup(r.text, 'lxml')
for p in soup.select('p'):
res = re.search("([a-z]{2,15})(/ .{1,15}/ .{3,15}[\u4e00-\u9fa5])", p.text)
if res:
dic[res.group(1)] = p.text.strip()
with open("words4.json", "w", encoding="utf-8") as f:
json.dump(dic, f)
if __name__ == '__main__':
with open("words4.json", "r") as f:
dic = json.load(f)
while True:
print("*" * 33)
pattern = input("\n请输入你要查询的单词,格式举例:man\n").strip()
if len(pattern) > 1:
print("-" * 9 + f"以{pattern}开头的单词" + "-" * 9)
for k in dic.keys():
if dic[k].startswith(pattern):
t = dic[k].replace(k, "")
print(k, t, sep=" ")
print("-" * 9 + f"以{pattern}结尾的单词" + "-" * 9)
for k in dic.keys():
if dic[k].endswith(pattern):
t = dic[k].replace(k, "")
print(k, t, sep=" ")
sleep(0.01)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44