如何根据返回的script脚本,执行得到cookie值

做python爬虫的时候返回的结果,想得到对应的cookie值
"<script>document.cookie=('_')+('_')+('j')+('s')+('l')+('_')+('c')+('l')+('e')+('a')+('r')+('a')+('n')+('c')+('e')+('=')+(-~{}+'')+(1+5+'')+([2]*(3)+'')+((+[])+'')+((1<<3)+'')+((1|2)+'')+((+[])+'')+(1+1+'')+(~~{}+'')+(-~(8)+'')+('.')+(-~[7]+'')+(~~''+'')+(3+3+'')+('|')+('-')+(-~0+'')+('|')+('P')+('r')+(-~0+'')+('c')+('g')+('N')+('C')+('S')+(5+'')+('I')+('r')+('v')+('I')+('y')+('b')+('q')+('V')+('b')+(3+4+'')+(-~(3)+'')+('I')+((1|2)+'')+((1+[2]>>2)+'')+('h')+('O')+('N')+('Q')+('%')+((1+[2]>>2)+'')+('D')+(';')+('m')+('a')+('x')+('-')+('a')+('g')+('e')+('=')+(1+2+'')+([2]*(3)+'')+(~~''+'')+((+false)+'')+(';')+('p')+('a')+('t')+('h')+('=')+('/');location.href=location.pathname+location.searchscript>"


尝试

def getFormJS(text):
    js_code=re.findall(r'',text)[0]
    js=js_code.replace('document.cookie','val cookie')
    ctx=execjs.compile(js)
    cookie1=ctx.eval('cookie')
    return cookie1

报错

img

2.尝试

看了一些相关博客,大概是用execjs执行js代码。但是之前没有学过,自己理解尝试了并不行。
想得到执行后的cookie值
from urllib import request
from http import cookiejar
 
if __name__ == '__main__':
    # 声明一个CookieJar对象实例来保存cookie
    cookie = cookiejar.CookieJar()
    # 利用urllib.request库的HTTPCookieProcessor对象来创建cookie处理器,也就CookieHandler
    handler=request.HTTPCookieProcessor(cookie)
    # 通过CookieHandler创建opener
    opener = request.build_opener(handler)
    # 此处的open方法打开网页
    response = opener.open('http://www.XXXXX.com')
    # 打印cookie信息
    for item in cookie:
        print('Name = %s' % item.name)
        print('Value = %s' % item.value)