Skip to content

Instantly share code, notes, and snippets.

@tatic0
Created September 10, 2015 11:34
Show Gist options
  • Save tatic0/f31efbdb22e2a678ba47 to your computer and use it in GitHub Desktop.
Save tatic0/f31efbdb22e2a678ba47 to your computer and use it in GitHub Desktop.
ugly scritp to search for Wordreference translations from the command line
#!/usr/bin/env python
# -*- coding=utf-8 -*-
# F Varas 09 2015
# works:
# wget --user-agent="User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12" "http://www.wordreference.com/fres/sournois" -O sournois2.html
import sys
if len(sys.argv) <= 1:
print("Usage: %s <source language> <destination language> word" %sys.argv[0])
sys.exit(0)
slang = sys.argv[1] #"Source Language (fr, es, en, ...)"
dlang = sys.argv[2] #"Destination Language (es, en, fr, ...)"
fword = sys.argv[3]
import requests
headers = { 'User-Agent' : 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'}
#url = "http://www.wordreference.com/fres/sournois"
url = "http://www.wordreference.com/" + slang + dlang + "/" + fword
response = requests.get(url, headers=headers)
data = response.text
#print(data)
from BeautifulSoup import BeautifulSoup
gazpacho = BeautifulSoup(data)
# <div id="articleWRD">
article = gazpacho.find(id="articleWRD")
print article.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment