"""
要想用另一种方式去执行js,而不是使用execjs,
我们可以使用subprocess.run 去执行
node -e "console.log(require('./web.js').myFun(params))"
也可以先node 再
var web = require('./web.js');
web.myFun(video_urls) 即打印最终结果
两种方式的前提条件是:本地环境有node,且需要在js文件中加入 module.exports.myFun = decrypt_m3u8;
封装了平时对execjs的使用
"""
import os
# from node_vm2 import VM, NodeVM
import re
import execjs # pip install PyExecJS
class ExecjsUtils:
def __init__(self, js_file_path: str, cwd=None):
self.__choice_execjs_runtime()
with open(js_file_path, 'r', encoding='utf-8') as f:
print(execjs.get().name) # Node.js (V8)
node = execjs.get() # 安装nodejs后,会得到运行环境名为:Node.js (V8)
self.__ctx = node.compile(f.read())
def __choice_execjs_runtime(self):
os.environ['EXECJS_RUNTIME'] = "Node"
def call(self, *args, **kwargs):
result = self.__ctx.call(*args, **kwargs)
return result
import requests
from lxml import etree
from urllib.parse import urlencode
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
requests = requests.session()
class Spider:
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Pragma": "no-cache",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
"sec-ch-ua": "\"Not_A Brand\";v=\"99\", \"Google Chrome\";v=\"109\", \"Chromium\";v=\"109\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\""
}
head_url = 'https://www.nmpa.gov.cn/'
def __init__(self):
pass
def first_req_header(self):
response = requests.get(self.head_url, headers=self.headers, verify=False)
print("第一次响应状态;",response.status_code)
meta_content = re.search(r'<meta content="(.*?)">', response.text).group(1)
js_code = re.search(r'r="m">(.*?)</s', response.text).group(1)
print("re匹配 meta_content:", meta_content)
print("re匹配自执行js_code:", js_code)
end_code = f"""
Meta$content = "{meta_content}";
{js_code};;
function get_cookie(){{
return document.cookie;
}}
;;
globalThis.get_cookie = get_cookie;
function get_mme(){{
XMLHttpRequest.prototype.open("GET","http://www.fangdi.com.cn/service/freshHouse/queryProjectById.actin",true);
return XMLHttpRequest.prototype.uri;
}}
globalThis.get_mme = get_mme;
"""
return end_code
def get_js_utils(self,end_code):
head_file = 'rs5_debugger.js'
# head_file = 'rs_debugger_fina.js'
js_file_path = 'rs5_debugger_dev.js'
with open(head_file, 'r', encoding='utf-8') as r, open(js_file_path, 'w', encoding='utf-8') as w:
head_code = r.read()
w.write(head_code + end_code)
utils = ExecjsUtils(js_file_path)
return utils
def second_req_header(self,end_code:str):
self.utils = self.get_js_utils(end_code)
cookie_str: str = self.utils.call("get_cookie")
cookie_k, cookie_v = cookie_str.split(";", 1)[-1].split('=', 1)
cookie_k = cookie_k.strip()
cookie_v = cookie_v.strip()
print("最终cookie_t:", len(cookie_v),cookie_k, cookie_v)
requests.cookies.set(cookie_k, cookie_v)
self.headers.update(
{"Referer": "https://www.nmpa.gov.cn/","Sec-Fetch-Site": "same-origin"})
response = requests.get(self.head_url, headers=self.headers, verify=False)
response.encoding = 'utf-8'
print(f"第二次响应状态:{response.status_code}")
print(f"第二次响应内容:{response.text}")
def mm_req(self):
# js_file_path = 'rs_debugger_dev.js'
# js_file_path = 'rs_debugger_dev.js'
# utils = ExecjsUtils(js_file_path)
mme: str = self.utils.call("get_mme")
mme = mme.strip("http://www.fangdi.com.cn/service/freshHouse/queryProjectById.actin?MmEwMD=")
print("MmEwMD:",len(mme),mme)
simple_url = 'http://www.fangdi.com.cn/service/freshHouse/queryProjectById.actin'
params = {
"MmEwMD": mme
}
_url = simple_url + f'?{urlencode(params)}'
headers = {
"Host": "www.fangdi.com.cn",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"Accept": "application/json, text/javascript, */*; q=0.01",
"X-Requested-With": "XMLHttpRequest",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
"Origin": "http://www.fangdi.com.cn",
"Referer": "http://www.fangdi.com.cn/new_house/new_house_detail.html?project_id=b87cb3d04f878ca6",
"Accept-Language": "zh-CN,zh;q=0.9",
}
_data = {
"projectID": "b87cb3d04f878ca6"
}
data = urlencode(_data)
response = requests.post(_url, headers=headers, data=data, verify=False)
print(response.status_code,response.text)
def main(self):
end_code = self.first_req_header()
self.second_req_header(end_code)
# self.mm_req()
# self.mm_req()
if __name__ == '__main__':
Spider().main()
'''
mme: 355 http://www.fangdi.com.cn/service/freshHouse/queryProjectById.actin?MmEwMD=4nh651SnrwUUH9smp9lvSFmFjFs62QChZMeWxc4EAaphPieUuTRPA5pNa0.yRQD5u5yqdmwHptNGrqnc0qy3vw.ENIdddd6ddddedddddIdddduuXbiSXZ8Mwg3QBxRgozu8.Jl4FYqbXmi.Oel_sUT62knBgof3G5K1Nhv4nj6yopFyCYNQdnbVIgRTTBkrQJfojCuaaqPes1s5ss8NJzl.IIdddd6ddddedddddIddddeB_ZjsA8DeGJ7qOG41oD_5wiKodc9SCcxk1jgs8Kvfv
mme: 355 http://www.fangdi.com.cn/service/freshHouse/queryProjectById.actin?MmEwMD=4nh651SnrwUUH9smp9lvSFmFjFs62QChZMeWxc4EAaphPieUuTRPA5pNa0.yRQD5u5yqdmwHptNGrqnc0qy3vw.ENIdddd6ddddedddddIdddduuXbiSXZ8Mwg3QBxRgozu8.Jl4FYqbXmi.Oel_sUT62knBgof3G5K1Nhv4nj6yopFyCYNQdnbVIgRTTBkrQJfojCuaaqPes1s5ss8NJzl.IIdddd6ddddedddddIddddeB_ZjsA8DeGJ7qOG41oD_5wiKodc9SCcxk1jgs8Kvfv
'''
没有合适的资源?快使用搜索试试~ 我知道了~
瑞数5代(rs5)补环境+后缀算法(含python爬虫与JS算法)
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共7个文件
js:5个
py:2个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 167 浏览量
2024-05-18
14:06:18
上传
评论
收藏 881KB ZIP 举报
温馨提示
ZIP包内含瑞数5代Cookie补环境算法、后缀算法还原!Python爬虫有完整rs5网站爬虫示例与JS调用算法,直接可以使用!有任何问题可以联系作者
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 7 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/6b30c05361b045b79c13c6acd871228b_qiulin_wu.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
吴秋霖
- 粉丝: 2w+
- 资源: 80
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)