當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。