This commit is contained in:
2022-02-25 00:20:34 +08:00
parent 74707df3fc
commit 711a072237
4 changed files with 0 additions and 66 deletions

View File

@@ -1,48 +0,0 @@
"""
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 requests
import urllib.request
import os
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
html = urllib.request.urlopen("https://www.guanjihuan.com/archives/4418").read().decode('utf-8')
soup = BeautifulSoup(html, features='lxml')
all_a_tag = soup.find_all('a', href=True)
for a_tag in all_a_tag:
href = a_tag['href']
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_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'} # 头部信息
request = urllib.request.Request(href,headers=header)
reponse = urllib.request.urlopen(request).read()
soup2 = BeautifulSoup(reponse, features='lxml')
span = soup2.find_all('span', {"class":"speaker brefile fas fa-volume-up hideOnAmp"})
for span0 in span:
href2 = span0['data-src-mp3']
if re.search('https://www.ldoceonline.com/media/english/breProns/', href2):
print(href2)
r = requests.get(href2, headers=header, stream=True)
with open('words_mp3_breProns/'+href[39:]+'.mp3', 'wb') as f:
for chunk in r.iter_content(chunk_size=32):
f.write(chunk)
break
span = soup2.find_all('span', {"class":"speaker amefile fas fa-volume-up hideOnAmp"})
for span0 in span:
href2 = span0['data-src-mp3']
if re.search('https://www.ldoceonline.com/media/english/ameProns/', href2):
print(href2)
r = requests.get(href2, headers=header, stream=True)
with open('words_mp3_ameProns/'+href[39:]+'.mp3', 'wb') as f:
for chunk in r.iter_content(chunk_size=32):
f.write(chunk)
break
print()

View File

@@ -1,40 +0,0 @@
"""
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('<h2>.*?<h2>', 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('<p>.*?</p>', content, re.S)[0][3:-4]
time.sleep(2)
print(translation, '\n')
time.sleep(1) # 调节间隔时间
pygame.mixer.music.stop()

View File

@@ -1,26 +0,0 @@
"""
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
"""
import pygame
import time
import os
import random
# directory = 'words_mp3_breProns/' # 英音
directory = 'words_mp3_ameProns/' # 美音
pygame.mixer.init()
for root, dirs, files in os.walk(directory):
num_array = list(range(len(files)))
random.shuffle(num_array) # 随机播放
j0 = 0
for i0 in num_array:
j0 += 1
print(j0)
print(files[i0][:-4])
print('https://www.ldoceonline.com/dictionary/'+files[i0][:-4], '\n')
track = pygame.mixer.music.load(directory+files[i0])
pygame.mixer.music.play()
time.sleep(3) # 调节间隔时间
pygame.mixer.music.stop()

View File

@@ -1,8 +0,0 @@
# Words in webpage: https://www.guanjihuan.com/archives/4418
# installation:
# (1) pip install pygame
# (2) pip install --upgrade guan
import guan
guan.play_academic_words()
# guan.play_academic_words(bre_or_ame='ame', random_on=0, show_translation=1, show_link=1, translation_time=2, rest_time=1)