当前位置: 首页>>代码示例>>Python>>正文


Python execjs.compile方法代码示例

本文整理汇总了Python中execjs.compile方法的典型用法代码示例。如果您正苦于以下问题:Python execjs.compile方法的具体用法?Python execjs.compile怎么用?Python execjs.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在execjs的用法示例。


在下文中一共展示了execjs.compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: happigo

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def happigo(fun, mobile):
    s = requests.session()
    s.headers = headers
    g = s.get('https://www.happigo.com/register/')
    send_mobile_key = re.findall('<input type="hidden" id="send_mobile_key" name="send_mobile_key" value="(.*?)" />',g.text)[0]
    m = s.get('https://ecimg.happigo.com/resource/web/js/md5.js')
    ctx = execjs.compile(m.text)
    send_mobile_token = ctx.call('hex_md5',send_mobile_key+mobile)
    data = {'token':'ok','mobile':mobile,'send_mobile_key':send_mobile_key,'send_mobile_token':send_mobile_token,'v':'1.0','t':str(int(time.time()*1000))}
    s.headers['referer'] = 'https://www.happigo.com/register/'
    s.headers['x-requested-with'] = 'XMLHttpRequest'
    s.headers['x-tingyun-id'] = 'JEZ7HInwfsc;r=747473032'
    s.cookies['traceguid'] = 'webportalef19626169fd56134181bae74abdfd59'
    r = s.post('https://www.happigo.com/shop/index.php?act=login&op=send_auth_code&type=2',data=data)
    decoded_data = codecs.decode(bytes(r.text,encoding='utf-8'), 'utf-8-sig')
    if json.loads(decoded_data)['state'] == 'true':
        return success(fun, r.text)
    failure(fun, r.text) 
开发者ID:Brightest08,项目名称:message,代码行数:20,代码来源:message_api.py

示例2: stock_us_spot

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def stock_us_spot() -> pd.DataFrame:
    """
    新浪财经-所有美股的数据, 注意延迟 15 分钟
    :return: 美股所有股票实时行情
    :rtype: pandas.DataFrame
    """
    big_df = pd.DataFrame()
    page_count = get_us_page_count()
    for page in tqdm(range(1, page_count + 1)):
        # page = "1"
        us_js_decode = "US_CategoryService.getList?page={}&num=20&sort=&asc=0&market=&id=".format(
            page
        )
        js_code = execjs.compile(js_hash_text)
        dict_list = js_code.call("d", us_js_decode)  # 执行js解密代码
        us_sina_stock_dict_payload.update({"page": "{}".format(page)})
        res = requests.get(
            us_sina_stock_list_url.format(dict_list), params=us_sina_stock_dict_payload
        )
        data_json = json.loads(res.text[res.text.find("({") + 1: res.text.rfind(");")])
        big_df = big_df.append(pd.DataFrame(data_json["data"]), ignore_index=True)
    return big_df 
开发者ID:jindaxiang,项目名称:akshare,代码行数:24,代码来源:us_stock_sina.py

示例3: get_sck

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def get_sck(skey):

    # 读取js脚本
    md5 = get_js('decrypt/md5.js')

    # 加载js脚本引擎
    ctx = compile(md5)

    # 调用js脚本中某个函数
    # 第1个参数为函数名,第2到第n个参数为该函数依次所需的参数
    result = ctx.call('hex_md5', str(skey))

    return str(result)


# 获取g_tk值,这里的g_tk值算法由vip.qq.com获取,暂不清楚是否能直接用于其他域名 
开发者ID:shengqiangzhang,项目名称:examples-of-web-crawlers,代码行数:18,代码来源:decrypt.py

示例4: get_csrf_token

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def get_csrf_token(skey):
    # 读取js脚本
    js = get_js('decrypt/getCSRFToken.js')

    # 加载js脚本引擎
    ctx = compile(js)

    # 调用js脚本中某个函数
    # 第1个参数为函数名,第2到第n个参数为该函数依次所需的参数
    tmp_data = ctx.call('getCSRFToken', str(skey))


    # 读取js脚本
    js = get_js('decrypt/md5.js')

    # 加载js脚本引擎
    ctx = compile(js)

    # 调用js脚本中某个函数
    # 第1个参数为函数名,第2到第n个参数为该函数依次所需的参数
    result = ctx.call('hex_md5', str(tmp_data))

    return result 
开发者ID:shengqiangzhang,项目名称:examples-of-web-crawlers,代码行数:25,代码来源:decrypt.py

示例5: request

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def request(self, content, retries=3):
        '''
        请求网页得到翻译结果
        :param content: 
        :param timeout: 每次请求的超时秒数
        :param retries: 最大重试次数,请求失败后有效
        :return: {'out':'翻译结果','word_mean':'单词解释'} 两者选一
        '''
        if time.time() - self.tkk_updatetime > 3600:
            self.update_tkk()
        for _ in range(retries):
            try:
                tk = execjs.compile(open(r"translate_google.js").read()).call('Ho', content, self.tkk)
                content = urllib.parse.quote(content)
                # sl:原始语言 tl:目标语言
                url = 'https://translate.google.cn/translate_a/single?client=webapp&sl=auto&tl=zh-CN&hl=en&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&otf=2&ssel=0&tsel=4&kc=1&tk=%s&q=%s' % (
                tk, content)
                res_trans = requests.get(url, **REQUEST_PARAMS)
                res_trans = res_trans.json()[0]
                res_trans_target = [i[0] for i in res_trans[:-1]]
                res_trans_target = ''.join(res_trans_target)
                return dict(out=res_trans_target)
            except Exception as e:
                pass
        return {} 
开发者ID:lkjie,项目名称:paper-translator,代码行数:27,代码来源:Translator.py

示例6: get_us_page_count

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def get_us_page_count() -> int:
    """
    新浪财经-美股-总页数
    :return: 美股总页数
    :rtype: int
    """
    page = "1"
    us_js_decode = f"US_CategoryService.getList?page={page}&num=20&sort=&asc=0&market=&id="
    js_code = execjs.compile(js_hash_text)
    dict_list = js_code.call("d", us_js_decode)  # 执行js解密代码
    us_sina_stock_dict_payload.update({"page": "{}".format(page)})
    res = requests.get(
        us_sina_stock_list_url.format(dict_list), params=us_sina_stock_dict_payload
    )
    data_json = json.loads(res.text[res.text.find("({") + 1: res.text.rfind(");")])
    if not isinstance(int(data_json["count"]) / 20, int):
        page_count = int(int(data_json["count"]) / 20) + 1
    else:
        page_count = int(int(data_json["count"]) / 20)
    return page_count 
开发者ID:jindaxiang,项目名称:akshare,代码行数:22,代码来源:us_stock_sina.py

示例7: get_us_stock_name

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def get_us_stock_name() -> pd.DataFrame:
    """
    u.s. stock's english name, chinese name and symbol
    you should use symbol to get apply into the next function
    :return: stock's english name, chinese name and symbol
    :rtype: pandas.DataFrame
    """
    big_df = pd.DataFrame()
    page_count = get_us_page_count()
    for page in tqdm(range(1, page_count + 1)):
        # page = "1"
        us_js_decode = "US_CategoryService.getList?page={}&num=20&sort=&asc=0&market=&id=".format(
            page
        )
        js_code = execjs.compile(js_hash_text)
        dict_list = js_code.call("d", us_js_decode)  # 执行js解密代码
        us_sina_stock_dict_payload.update({"page": "{}".format(page)})
        res = requests.get(
            us_sina_stock_list_url.format(dict_list), params=us_sina_stock_dict_payload
        )
        data_json = json.loads(res.text[res.text.find("({") + 1: res.text.rfind(");")])
        big_df = big_df.append(pd.DataFrame(data_json["data"]), ignore_index=True)
    return big_df[["name", "cname", "symbol"]] 
开发者ID:jindaxiang,项目名称:akshare,代码行数:25,代码来源:us_stock_sina.py

示例8: _get_zh_bond_hs_cov_page_count

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def _get_zh_bond_hs_cov_page_count() -> int:
    """
    行情中心首页-债券-沪深可转债的总页数
    http://vip.stock.finance.sina.com.cn/mkt/#hskzz_z
    :return: 总页数
    :rtype: int
    """
    params = {
        "node": "hskzz_z",
    }
    res = requests.get(zh_sina_bond_hs_cov_count_url, params=params)
    page_count = int(re.findall(re.compile(r"\d+"), res.text)[0]) / 80
    if isinstance(page_count, int):
        return page_count
    else:
        return int(page_count) + 1 
开发者ID:jindaxiang,项目名称:akshare,代码行数:18,代码来源:zh_bond_cov_sina.py

示例9: bond_zh_hs_cov_daily

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def bond_zh_hs_cov_daily(symbol: str = "sh113542") -> pd.DataFrame:
    """
    新浪财经-债券-沪深可转债的历史行情数据, 大量抓取容易封IP
    http://vip.stock.finance.sina.com.cn/mkt/#hskzz_z
    :param symbol: 沪深可转债代码; e.g., sh010107
    :type symbol: str
    :return: 指定沪深可转债代码的日 K 线数据
    :rtype: pandas.DataFrame
    """
    res = requests.get(
        zh_sina_bond_hs_cov_hist_url.format(
            symbol, datetime.datetime.now().strftime("%Y_%m_%d")
        )
    )
    js_code = execjs.compile(hk_js_decode)
    dict_list = js_code.call(
        "d", res.text.split("=")[1].split(";")[0].replace('"', "")
    )  # 执行js解密代码
    data_df = pd.DataFrame(dict_list)
    data_df["date"] = data_df["date"].str.split("T", expand=True).iloc[:, 0]
    data_df.index = pd.to_datetime(data_df["date"])
    del data_df["date"]
    data_df.astype("float")
    return data_df 
开发者ID:jindaxiang,项目名称:akshare,代码行数:26,代码来源:zh_bond_cov_sina.py

示例10: get_zh_bond_hs_page_count

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def get_zh_bond_hs_page_count():
    """
    行情中心首页-债券-沪深债券的总页数
    http://vip.stock.finance.sina.com.cn/mkt/#hs_z
    :return: 总页数
    :rtype: int
    """
    params = {
        "node": "hs_z",
    }
    res = requests.get(zh_sina_bond_hs_count_url, params=params)
    page_count = int(re.findall(re.compile(r"\d+"), res.text)[0]) / 80
    if isinstance(page_count, int):
        return page_count
    else:
        return int(page_count) + 1 
开发者ID:jindaxiang,项目名称:akshare,代码行数:18,代码来源:zh_bond_sina.py

示例11: bond_zh_hs_daily

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def bond_zh_hs_daily(symbol="sh010107"):
    """
    新浪财经-债券-沪深债券的的历史行情数据, 大量抓取容易封IP
    http://vip.stock.finance.sina.com.cn/mkt/#hs_z
    :param symbol: 沪深债券代码; e.g., sh010107
    :type symbol: str
    :return: 指定沪深债券代码的日 K 线数据
    :rtype: pandas.DataFrame
    """
    res = requests.get(
        zh_sina_bond_hs_hist_url.format(
            symbol, datetime.datetime.now().strftime("%Y_%m_%d")
        )
    )
    js_code = execjs.compile(hk_js_decode)
    dict_list = js_code.call(
        "d", res.text.split("=")[1].split(";")[0].replace('"', "")
    )  # 执行js解密代码
    data_df = pd.DataFrame(dict_list)
    data_df["date"] = data_df["date"].str.split("T", expand=True).iloc[:, 0]
    data_df.index = pd.to_datetime(data_df["date"])
    del data_df["date"]
    data_df.astype("float")
    return data_df 
开发者ID:jindaxiang,项目名称:akshare,代码行数:26,代码来源:zh_bond_sina.py

示例12: MsgHandler

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def MsgHandler():
    html=HttpClient_Ist.Get(Referer+'/infocenter?via=toolbar',Referer)
    fkey=re.findall(r'<div class="f-item f-s-i" id=".*?" data-feedsflag=".*?" data-iswupfeed=".*?" data-key="(.*?)" data-specialtype=".*?" data-extend-info=".*?"',html)
    if not fkey:
        raise Exception, 'Fail to find any feeds'
    g_qzonetoken=re.search(r'window\.g_qzonetoken = \(function\(\)\{ try\{return (.*?);\} catch\(e\)',html)
    g_qzonetoken=g_qzonetoken.group(1)
    ctx = execjs.compile('function qz(){location = "./"; return '+g_qzonetoken+'}')
    qztoken=str(ctx.call("qz"))
    split_string=re.split(r'<div class="f-item f-s-i" id=".*?" data-feedsflag=".*?" data-iswupfeed=".*?" data-key=".*?" data-specialtype=".*?" data-extend-info=".*?"',html)
    for i in range (0,len(fkey)):
        try:
            btn_string = re.search(r'<a class="item qz_like_btn_v3.*?" data-islike="0" data-likecnt=".*?" data-showcount=".*?" data-unikey="(.*?)" data-curkey="(.*?)" data-clicklog="like" href="javascript:;">', split_string[i+1])
            if btn_string is None:
                continue
            abstime = re.search(r'data-abstime="(\d*?)"',split_string[i+1])
            if abstime is None:
                continue
            like(btn_string.group(1),btn_string.group(2),fkey[i],abstime.group(1),qztoken)
            logging.info('已点赞'+btn_string.group(2))
        except Exception, e:
            logging.error(str(e))

# -----------------
# 主程序
# ----------------- 
开发者ID:zeruniverse,项目名称:QBotWebWrap,代码行数:28,代码来源:qqbot.py

示例13: aes_enc

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def aes_enc(data, key, iv):
    bjs = get_jsfile('crypto.js')
    result = execjs.compile(bjs).call('enc', data, key, iv)
    return result 
开发者ID:Mocha-L,项目名称:wechat_wegoing,代码行数:6,代码来源:run.py

示例14: __init__

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def __init__(self):
        self.tkk = gettkk.get_tkk()  #从服务器获取TKK
        self.ctx = execjs.compile("""
        function b(a, b) {
            for (var d = 0; d < b.length - 2; d += 3) {
                var c = b.charAt(d + 2),
                    c = "a" <= c ? c.charCodeAt(0) - 87 : Number(c),
                    c = "+" == b.charAt(d + 1) ? a >>> c : a << c;
                a = "+" == b.charAt(d) ? a + c & 4294967295 : a ^ c
            }
            return a
        }

        function tk(a,TKK) {
            for (var e = TKK.split("."), h = Number(e[0]) || 0, g = [], d = 0, f = 0; f < a.length; f++) {
                var c = a.charCodeAt(f);
                128 > c ? g[d++] = c : (2048 > c ? g[d++] = c >> 6 | 192 : (55296 == (c & 64512) && f + 1 < a.length && 56320 == (a.charCodeAt(f + 1) & 64512) ? (c = 65536 + ((c & 1023) << 10) + (a.charCodeAt(++f) & 1023), g[d++] = c >> 18 | 240, g[d++] = c >> 12 & 63 | 128) : g[d++] = c >> 12 | 224, g[d++] = c >> 6 & 63 | 128), g[d++] = c & 63 | 128)
            }
            a = h;
            for (d = 0; d < g.length; d++) a += g[d], a = b(a, "+-a^+6");
            a = b(a, "+-3^+b+-f");
            a ^= Number(e[1]) || 0;
            0 > a && (a = (a & 2147483647) + 2147483648);
            a %= 1E6;
            return a.toString() + "." + (a ^ h)
        }
    """) 
开发者ID:ziliwang,项目名称:GoogleFreeTrans,代码行数:29,代码来源:CalcTk.py

示例15: get_node_ctx

# 需要导入模块: import execjs [as 别名]
# 或者: from execjs import compile [as 别名]
def get_node_ctx():
        global ctx
        if ctx:
            return ctx
        with open(mainjs, encoding='utf-8') as f:
            jscode = f.read()
        ctx = execjs.compile(jscode, cwd=hnode)
        return ctx 
开发者ID:cilame,项目名称:vrequest,代码行数:10,代码来源:pyjsdefusion.py


注:本文中的execjs.compile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。