Created
September 10, 2015 11:34
-
-
Save tatic0/f31efbdb22e2a678ba47 to your computer and use it in GitHub Desktop.
ugly scritp to search for Wordreference translations from the command line
This file contains hidden or 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/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