Update gtoken.py (#95)
This commit is contained in:
parent
759a0baf46
commit
94bd300e75
@ -38,8 +38,8 @@ class TokenAcquirer(object):
|
||||
950629.577246
|
||||
"""
|
||||
|
||||
RE_TKK = re.compile(r'TKK=eval\(\'\(\(function\(\)\{(.+?)\}\)\(\)\)\'\);',
|
||||
re.DOTALL)
|
||||
RE_TKK = re.compile(r'tkk:\'(.+?)\'', 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()
|
||||
@ -55,6 +55,12 @@ class TokenAcquirer(object):
|
||||
return
|
||||
|
||||
r = self.session.get(self.host)
|
||||
|
||||
raw_tkk = self.RE_TKK.search(r.text)
|
||||
if raw_tkk:
|
||||
self.tkk = raw_tkk.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(=)
|
||||
|
Loading…
Reference in New Issue
Block a user