Skip to content

Commit

Permalink
Fix changed gtoken
Browse files Browse the repository at this point in the history
  • Loading branch information
wizyoung committed Sep 21, 2018
1 parent b45d24a commit 62002e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/googletrans/gtoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class TokenAcquirer(object):

RE_TKK = re.compile(r'TKK=eval\(\'\(\(function\(\)\{(.+?)\}\)\(\)\)\'\);',
re.DOTALL)
RE_RAWTKK = re.compile(r'TKK=\'([^\']*)\';',re.DOTALL)

def __init__(self, tkk='0', session=None, host='translate.google.com'):
self.session = session or requests.Session()
Expand All @@ -55,6 +56,12 @@ def _update(self):
return

r = self.session.get(self.host)

rawtkk = self.RE_RAWTKK.search(r.text)
if rawtkk:
self.tkk = rawtkk.group(1)
return

# this will be the same as python code after stripping out a reserved word 'var'
code = unicode(self.RE_TKK.search(r.text).group(1)).replace('var ', '')
# unescape special ascii characters such like a \x3d(=)
Expand Down
Binary file removed src/googletrans/gtoken.pyc
Binary file not shown.

0 comments on commit 62002e6

Please sign in to comment.