Created
September 7, 2019 15:32
-
-
Save niyumard/2461dae492abd271e089d81ca5b94e99 to your computer and use it in GitHub Desktop.
This script extracts audio for French words from Linguee dictionary
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
#!/usr/bin/python3 | |
import requests, sys, os | |
from bs4 import BeautifulSoup | |
try: | |
r = requests.get("https://www.linguee.com/english-french/search", data={'query': sys.argv[1]}) | |
#print(r.status_code, r.reason) | |
if r.status_code == 200 and r.reason == 'OK': | |
pass | |
else: | |
print("Failed connecting to the server") | |
except: | |
print("Huh?") | |
soup = BeautifulSoup(r.text, 'html.parser') | |
if 'class="noresults wide_in_main"' not in soup.text: | |
# print(soup.find(id="dictionary")) | |
mydivs = soup.findAll("a", {"class": "audio"}) | |
os.system("mpv http://www.linguee.com/mp3/"+mydivs[0]['id']+".mp3") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment