-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_paraphrasing.py
More file actions
38 lines (33 loc) · 995 Bytes
/
python_paraphrasing.py
File metadata and controls
38 lines (33 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#python34
import sys
from PyQt4.QtGui import QApplication
from PyQt4.QtCore import QUrl
from PyQt4.QtWebKit import QWebPage
import bs4 as bs
import urllib.request
import time
#function for js call
class Client(QWebPage):
def __init__(self, url):
self.app = QApplication(sys.argv)
QWebPage.__init__(self)
self.loadFinished.connect(self.on_page_load)
self.mainFrame().load(QUrl(url))
self.app.exec_()
def on_page_load(self):
self.app.quit()
def translate(targetLang,mainText):
# targetLang = "zh-CN"
# mainText = "main test text to paraphrase"
url = "https://translate.google.com/#auto/" + targetLang + "/" + mainText
client_response = Client(url)
source = client_response.mainFrame().toHtml()
soup = bs.BeautifulSoup(source, 'html.parser')
result = soup.find("span", {"id":"result_box"})
return result.text
#print (result.text)
def paraPhrase(givenText):
newText = translate("en",translate("zh-CN",givenText))
return (newText)
# textt = paraPhrase("")
# print (textt)