diff --git a/language_learning/2021.12.08_academic_words/download_word_mp3.py b/language_learning/2021.12.08_academic_words/download_word_mp3.py index 52629ef..98df16a 100644 --- a/language_learning/2021.12.08_academic_words/download_word_mp3.py +++ b/language_learning/2021.12.08_academic_words/download_word_mp3.py @@ -18,7 +18,7 @@ for a_tag in all_a_tag: if re.search('https://www.ldoceonline.com/dictionary/', href): print(href[39:]) exist_1 = os.path.exists('words_mp3_breProns/'+href[39:]+'.mp3') - exist_2 = os.path.exists('words_mp3_breProns/'+href[39:]+'.mp3') + exist_2 = os.path.exists('words_mp3_ameProns/'+href[39:]+'.mp3') if exist_1 and exist_2: continue header = {'User-Agent':'Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'} # 头部信息 diff --git a/language_learning/2021.12.08_academic_words/play_mp3.py b/language_learning/2021.12.08_academic_words/play_mp3_at random_without_translation.py similarity index 100% rename from language_learning/2021.12.08_academic_words/play_mp3.py rename to language_learning/2021.12.08_academic_words/play_mp3_at random_without_translation.py diff --git a/language_learning/2021.12.08_academic_words/play_mp3_with_sequence_and_translation.py b/language_learning/2021.12.08_academic_words/play_mp3_with_sequence_and_translation.py new file mode 100644 index 0000000..c305770 --- /dev/null +++ b/language_learning/2021.12.08_academic_words/play_mp3_with_sequence_and_translation.py @@ -0,0 +1,40 @@ +""" +This code is supported by the website: https://www.guanjihuan.com +The newest version of this code is on the web page: https://www.guanjihuan.com/archives/18038 +""" + +from bs4 import BeautifulSoup +import re +import urllib.request +import os +import pygame +import time +import ssl +import random +ssl._create_default_https_context = ssl._create_unverified_context +html = urllib.request.urlopen("https://www.guanjihuan.com/archives/4418").read().decode('utf-8') + +# directory = 'words_mp3_breProns/' # 英音 +directory = 'words_mp3_ameProns/' # 美音 +pygame.mixer.init() +soup = BeautifulSoup(html, features='lxml') +contents = re.findall('

.*?

', html, re.S) +# random.shuffle(contents) # 随机播放 +for content in contents: + soup2 = BeautifulSoup(content, features='lxml') + all_h2 = soup2.find_all('h2') + for h2 in all_h2: + if re.search('\d*. ', h2.get_text()): + word = re.findall('[a-zA-Z].*', h2.get_text(), re.S)[0] + exist = os.path.exists(directory+word+'.mp3') + if not exist: + continue + print(h2.get_text()) + # print('https://www.ldoceonline.com/dictionary/'+word) + track = pygame.mixer.music.load(directory+word+'.mp3') + pygame.mixer.music.play() + translation = re.findall('

.*?

', content, re.S)[0][3:-4] + time.sleep(2.5) + print(translation, '\n') + time.sleep(0.5) # 调节间隔时间 + pygame.mixer.music.stop() \ No newline at end of file