Python execjs.compile() Examples
The following are 30
code examples of execjs.compile().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
execjs
, or try the search function
.
Example #1
Source File: Translator.py From paper-translator with MIT License | 6 votes |
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 {}
Example #2
Source File: decrypt.py From examples-of-web-crawlers with MIT License | 6 votes |
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
Example #3
Source File: decrypt.py From examples-of-web-crawlers with MIT License | 6 votes |
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获取,暂不清楚是否能直接用于其他域名
Example #4
Source File: message_api.py From message with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: us_stock_sina.py From akshare with MIT License | 6 votes |
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
Example #6
Source File: zh_bond_sina.py From akshare with MIT License | 6 votes |
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
Example #7
Source File: zh_bond_sina.py From akshare with MIT License | 6 votes |
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
Example #8
Source File: zh_bond_cov_sina.py From akshare with MIT License | 6 votes |
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
Example #9
Source File: zh_bond_cov_sina.py From akshare with MIT License | 6 votes |
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
Example #10
Source File: us_stock_sina.py From akshare with MIT License | 6 votes |
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"]]
Example #11
Source File: us_stock_sina.py From akshare with MIT License | 6 votes |
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
Example #12
Source File: wenshu.py From Wenshu_Spider with MIT License | 5 votes |
def __init__(self, **kwargs): super().__init__(**kwargs) self.year_list = ['1996', '1997', '1998', '1999', '2000'] self.guid = 'aaaabbbb-aaaa-aaaabbbb-aaaabbbbcccc' with open('Wenshu\spiders\get_vl5x.js', encoding='utf-8') as f: jsdata_1 = f.read() with open('Wenshu\spiders\get_docid.js', encoding='utf-8') as f: jsdata_2 = f.read() self.js_1 = execjs.compile(jsdata_1) self.js_2 = execjs.compile(jsdata_2)
Example #13
Source File: run.py From wechat_wegoing with MIT License | 5 votes |
def aes_enc(data, key, iv): bjs = get_jsfile('crypto.js') result = execjs.compile(bjs).call('enc', data, key, iv) return result
Example #14
Source File: zh_stock_a_sina.py From akshare with MIT License | 5 votes |
def _get_zh_a_page_count() -> int: """ 所有股票的总页数 http://vip.stock.finance.sina.com.cn/mkt/#hs_a :return: 需要抓取的股票总页数 :rtype: int """ res = requests.get(zh_sina_a_stock_count_url) 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
Example #15
Source File: air_zhenqi.py From akshare with MIT License | 5 votes |
def air_quality_watch_point(city: str = "杭州", start_date: str = "2018-01-01", end_date: str = "2020-04-27") -> pd.DataFrame: """ 真气网-监测点空气质量-细化到具体城市的每个监测点 https://www.zq12369.com/ :param city: 调用 air_city_list 接口获取 :type city: str :param start_date: e.g., "2019-03-27" :type start_date: str :param end_date: e.g., ""2020-03-27"" :type end_date: str :return: 指定城市指定日期区间的观测点空气质量 :rtype: pandas.DataFrame """ url = "https://www.zq12369.com/api/zhenqiapi.php" file_data = _get_file_content(file_name="crypto.js") ctx = execjs.compile(file_data) method = "GETCITYPOINTAVG" ctx.call("encode_param", method) ctx.call("encode_param", start_date) ctx.call("encode_param", end_date) city_param = ctx.call("encode_param", city) ctx.call("encode_secret", method, city_param, start_date, end_date) payload = { "appId": "a01901d3caba1f362d69474674ce477f", "method": ctx.call("encode_param", method), "city": city_param, "startTime": ctx.call("encode_param", start_date), "endTime": ctx.call("encode_param", end_date), "secret": ctx.call("encode_secret", method, city_param, start_date, end_date), } headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36" } r = requests.post(url, data=payload, headers=headers) data_text = r.text data_json = demjson.decode(ctx.call("decode_result", data_text)) temp_df = pd.DataFrame(data_json["rows"]) return temp_df
Example #16
Source File: zh_stock_index_sina.py From akshare with MIT License | 5 votes |
def get_zh_index_page_count(): """ 所有指数的总页数 http://vip.stock.finance.sina.com.cn/mkt/#hs_s :return: int 需要抓取的指数的总页数 """ res = requests.get(zh_sina_index_stock_count_url) 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
Example #17
Source File: zh_stock_index_sina.py From akshare with MIT License | 5 votes |
def stock_zh_index_daily(symbol="sh000922"): """ 从新浪财经-指数获取某个指数的历史行情数据, 大量抓取容易封IP :param symbol: str e.g., sz399998 :return: pandas.DataFrame open high low close volume date 2015-06-16 2526.056 2577.092 2469.216 2487.513 2224345088 2015-06-17 2476.863 2567.842 2422.229 2560.914 2181699840 2015-06-18 2553.739 2587.655 2480.321 2480.674 2032781312 2015-06-19 2431.218 2453.794 2286.967 2287.758 1687013248 2015-06-23 2280.189 2341.795 2156.396 2341.359 1627453440 ... ... ... ... ... 2019-11-11 1210.968 1210.968 1182.442 1182.718 415074658 2019-11-12 1184.118 1196.425 1184.005 1195.790 397246387 2019-11-13 1195.925 1195.925 1180.293 1185.293 334027614 2019-11-14 1185.788 1187.431 1178.414 1180.791 271514767 2019-11-15 1181.090 1181.739 1165.898 1166.536 338309880 """ params = {"d": "2020_2_4"} res = requests.get(zh_sina_index_stock_hist_url.format(symbol), params=params) 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 = data_df.astype("float") return data_df
Example #18
Source File: zhihu_login.py From zhihu-login with MIT License | 5 votes |
def _encrypt(form_data: dict): with open('./encrypt.js') as f: js = execjs.compile(f.read()) return js.call('b', urlencode(form_data))
Example #19
Source File: jstool.py From TTBot with GNU General Public License v3.0 | 5 votes |
def py_to_js(js_file_path,js_func,*params): """ :usage: python传值给js脚本执行后获取其结果 :param data: @js_file_path : js脚本路径 @js_func : 要执行的js脚本的函数 @*params : python传给js函数的参数,可传多个 :return: @result : js脚本执行后的结果 """ js_script = get_js(js_file_path) JsContext = execjs.compile(js_script) result = JsContext.call(js_func,*params) return result
Example #20
Source File: util_trans.py From SubtitleTranslate with GNU General Public License v3.0 | 5 votes |
def __init__(self): self.ctx = execjs.compile(""" function TL(a) { var k = ""; var b = 406644; var b1 = 3293161072; var jd = "."; var $b = "+-a^+6"; var Zb = "+-3^+b+-f"; for (var e = [], f = 0, g = 0; g < a.length; g++) { var m = a.charCodeAt(g); 128 > m ? e[f++] = m : (2048 > m ? e[f++] = m >> 6 | 192 : (55296 == (m & 64512) && g + 1 < a.length && 56320 == (a.charCodeAt(g + 1) & 64512) ? (m = 65536 + ((m & 1023) << 10) + (a.charCodeAt(++g) & 1023), e[f++] = m >> 18 | 240, e[f++] = m >> 12 & 63 | 128) : e[f++] = m >> 12 | 224, e[f++] = m >> 6 & 63 | 128), e[f++] = m & 63 | 128) } a = b; for (f = 0; f < e.length; f++) a += e[f], a = RL(a, $b); a = RL(a, Zb); a ^= b1 || 0; 0 > a && (a = (a & 2147483647) + 2147483648); a %= 1E6; return a.toString() + jd + (a ^ b) }; function RL(a, b) { var t = "a"; var Yb = "+"; for (var c = 0; c < b.length - 2; c += 3) { var d = b.charAt(c + 2), d = d >= t ? d.charCodeAt(0) - 87 : Number(d), d = b.charAt(c + 1) == Yb ? a >>> d: a << d; a = b.charAt(c) == Yb ? a + d & 4294967295 : a ^ d } return a } """)
Example #21
Source File: util_trans.py From SubtitleTranslate with GNU General Public License v3.0 | 5 votes |
def __init__(self): self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'} self.tk_gen = TkGenerator() self.pattern = re.compile(r'\["(.*?)(?:\\n)') self.max_limited = 3500
Example #22
Source File: pccoldtv.py From pccold with MIT License | 5 votes |
def get_sign(rid, post_v, tt, ub9): docjs = execjs.compile(ub9) res2 = docjs.call('ub98484234') str3 = re.sub(r'\(function[\s\S]*toString\(\)', '\'', res2) md5rb = hashlib.md5((rid + '10000000000000000000000000001501' + tt + '2501' + post_v).encode('utf-8')).hexdigest() str4 = 'function get_sign(){var rb=\'' + md5rb + str3 str5 = re.sub(r'return rt;}[\s\S]*','return re;};', str4) str6 = re.sub(r'"v=.*&sign="\+', '', str5) docjs1 = execjs.compile(str6) sign = docjs1.call( 'get_sign', rid, '10000000000000000000000000001501', tt) return sign
Example #23
Source File: char.py From news_spider with MIT License | 5 votes |
def get_js_36_str(i): """ 整数、浮点数 js方式转36进制 :param i: :return: """ js_body = ''' function get_36_str(i) { return i.toString(36); }; ''' ctx = execjs.compile(js_body) return ctx.call("get_36_str", i)
Example #24
Source File: qqbot.py From QBotWebWrap with GNU General Public License v3.0 | 5 votes |
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)) # ----------------- # 主程序 # -----------------
Example #25
Source File: CalcTk.py From GoogleFreeTrans with MIT License | 5 votes |
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) } """)
Example #26
Source File: pyjsdefusion.py From vrequest with MIT License | 5 votes |
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
Example #27
Source File: porn91.py From crawler-py with MIT License | 5 votes |
def Decrypt(content): ctx=execjs.compile(js) encodes=re.findall('strencode\("(.*?)","(.*?)"',content)[0] video=ctx.call('strencode',encodes[0],encodes[1]) return video
Example #28
Source File: QQZoneSpider.py From QQZoneMood with MIT License | 5 votes |
def auto_get_cookie(self): self.web = webdriver.Chrome() self.web.get(self.host) self.web.switch_to.frame('login_frame') log = self.web.find_element_by_id("switcher_plogin") log.click() time.sleep(1) username = self.web.find_element_by_id('u') username.send_keys(self.username) ps = self.web.find_element_by_id('p') ps.send_keys(self.password) btn = self.web.find_element_by_id('login_button') time.sleep(1) btn.click() time.sleep(10) print("begin...") self.web.get('https://user.qzone.qq.com/{}/main'.format(self.username)) time.sleep(3) content = self.web.page_source qzonetoken = re.findall(re.compile("g_qzonetoken = \(function\(\)\{ try\{return \"(.*)?\""), content)[0] self.qzonetoken = qzonetoken cookie = '' # 获取cookie for elem in self.web.get_cookies(): cookie += elem["name"] + "=" + elem["value"] + ";" self.cookies = cookie print(cookie) print("Login success") self.logging.info("login_success") self.web.quit() # 手动添加cookie完成登陆
Example #29
Source File: QQZoneSpider.py From QQZoneMood with MIT License | 5 votes |
def extract_tid_from_unikey(self, unikey): tid = re.findall(re.compile('mood/(.*?)\.1'), unikey) if len(tid) > 0: return tid[0] else: return ''
Example #30
Source File: QQZoneSpider.py From QQZoneMood with MIT License | 5 votes |
def calculate_qzone_token(self): ctx = execjs.compile( '''function qzonetoken(){ location = 'http://user.qzone.qq.com/%s'; return %s}''' % ( self.raw_username, qzone_jother2)) return ctx.call("qzonetoken")