Skip to content

Instantly share code, notes, and snippets.

@niyumard
Created September 7, 2019 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niyumard/2461dae492abd271e089d81ca5b94e99 to your computer and use it in GitHub Desktop.
Save niyumard/2461dae492abd271e089d81ca5b94e99 to your computer and use it in GitHub Desktop.
This script extracts audio for French words from Linguee dictionary
#!/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