Last active
January 2, 2022 08:35
-
-
Save Neko288/d68ee0af38e8debde9b45746d98e6606 to your computer and use it in GitHub Desktop.
英単語を調べられます。英語to日本語も日本語to英語もできます。データ元はWebilio辞典。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, re | |
from bs4 import BeautifulSoup | |
source_url = 'https://ejje.weblio.jp/' | |
print('単語を翻訳したりできます。\n') | |
#Can Japnese ←-→ English Translate | |
def checkAlnum(word): | |
alnum = re.compile(r'^[a-zA-Z0-9]+$') | |
result = alnum.match(word) is not None | |
return result | |
def translate_en(tango_from): | |
res = requests.get(source_url+'content/'+tango_from) | |
soup = BeautifulSoup(res.content, "lxml") | |
imi = soup.find('td', class_='content-explanation ej') | |
henkei = soup.findAll('td', class_='intrstR') | |
print('意味 : '+imi.text) | |
print('変形 : ' + henkei[1].text+'\n') | |
def translate_jp(tango_from): | |
res = requests.get(source_url+'content/'+tango_from) | |
soup = BeautifulSoup(res.content, "lxml") | |
imi = soup.find('td', class_='content-explanation je') | |
print('意味 : '+imi.text+'\n') | |
while True: | |
while_tango = input('単語 : ') | |
if checkAlnum(while_tango)==False: | |
translate_jp(while_tango) | |
else: | |
translate_en(while_tango) | |
input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment