Created
March 2, 2015 16:13
-
-
Save chew-z/5c37b6f87e8262d3557d to your computer and use it in GitHub Desktop.
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
#coding: utf-8 | |
#translates using Google Translate via web | |
import requests | |
import re | |
import clipboard | |
from bs4 import BeautifulSoup | |
def translate(phrase): | |
if phrase == '': | |
raise Exception('Nothing found in clipboard') | |
userdata = {'q': phrase,'sl': 'fr' , 'tl': 'pl'} | |
response = requests.post("https://translate.google.com/", params=userdata) | |
print response.url | |
#print response.headers | |
return response.text | |
text = clipboard.get() | |
html = translate(text) | |
parsed_html = BeautifulSoup(html) | |
print parsed_html.body.find('div', attrs={'id':'gt-res-content'}).text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment