From 49a4a2bb45cd7299fbb3e15fc4e3c61bc2b30338 Mon Sep 17 00:00:00 2001 From: rnet Date: Sat, 30 Mar 2024 22:11:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20install=E5=91=BD=E4=BB=A4=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3build=E5=91=BD=E4=BB=A4=E7=94=A8=E4=BA=8E=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=BC=96=E8=AF=91;=20=E5=BC=95=E7=94=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .npmignore | 3 +++ README.md | 22 ++++++++++++++++------ browser/chrome/document.js | 2 +- browser/index.js | 4 +++- package.json | 7 +++---- test/documentAll.test.js | 2 +- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.npmignore b/.npmignore index 5da7fce..811f677 100644 --- a/.npmignore +++ b/.npmignore @@ -2,3 +2,6 @@ !bin/ !browser/ !utils/ +!binding.gyp +!README.md +!CHANGELOG.md diff --git a/README.md b/README.md index 913cf60..92b9f76 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,16 @@

-
+
sdenv

+[![NPM version](https://badge.fury.io/js/sdenv.svg)](http://badge.fury.io/js/sdenv) + + sdenv是一个javascript运行时补环境框架,与github上其它补环境框架存在较大区别,sdenv是站在巨人的肩膀上实现的,依赖于jsdom的强大dom仿真能力,sdenv可以真实模拟浏览器执行环境,作者在固定随机数与添加[sdenv-extend](https://github.com/pysunday/sdenv-extend)的部分插件后可以达到**瑞数vmp代码在sdenv运行生成的cookie值与浏览器生成的cookie值一致**。 * sdenv专用jsdom版本:[sdenv-jsdom](https://github.com/pysunday/sdenv-jsdom) * sdenv多端环境提取:[sdenv-extend](https://github.com/pysunday/sdenv-extend) +* 对瑞数算法逆向可参考项目:[rs-reverse](https://github.com/pysunday/rs-reverse) ## 依赖 @@ -14,24 +18,29 @@ sdenv是一个javascript运行时补环境框架,与github上其它补环境 编译node插件用的是[node-gyp](https://github.com/nodejs/node-gyp)工具,该工具需要有python环境和c环境(如windows系统需安装Visual Studio),请根据工具文档进行系统环境搭建。 +## 可能出现的问题 + +1. node-gyp报错:请确保操作系统有c++编译环境与python环境; +2. 安装缓慢及canvas报错:由于canvas安装会优先从github获取现成的包,因此请在安装前先设置代理或者其它国内源,如果安装仍然失败请使用npm官方源+代理方式重新尝试; + +有其它问题请提issues! + ## 使用 ### 源码方式 1. clone项目:`git clone https://github.com/pysunday/sdenv.git` 2. 安装依赖:`cd sdenv && npm i` -3. 执行编译,unix运行:`npm run build`,windows运行:`npm run build:win` -4. 运行样例: +3. 运行样例: * [运行本地代码](https://github.com/pysunday/sdenv/blob/main/example/use-local/README.md):`node example/use-local/index.js` * [运行网站代码](https://github.com/pysunday/sdenv/blob/main/example/use-remote/README.md):`node example/use-remote/index.js` -![样例调用](./static/example.png) +![样例调用](https://github.com/pysunday/sdenv/blob/main/static/example.png) ### npm包方式 1. 安装npm包:`npm i sdenv` -2. 进入文件夹`node-modules/sdenv`执行编译,unix运行:`npm run build`,windows运行:`npm run build:win` -3. 导入包方法: +2. 导入包方法: ```javascript const browser = require('sdenv/browser/'); const { jsdomFromText, jsdomFromUrl } = require('sdenv/utils/jsdom'); @@ -125,6 +134,7 @@ sdenv-extend初始化只执行一次,初始化成功后生成的环境对象 sdenv-extend具体功能可参考项目内[README文档](https://github.com/pysunday/sdenv-extend/blob/main/README.md)。 + ## 声明 该项目的开发基于瑞数vmp网站,不能保证在其它反爬虫产品稳定使用,出现问题请及时提issues或者提pull参与共建! diff --git a/browser/chrome/document.js b/browser/chrome/document.js index 35d56e9..1461adf 100644 --- a/browser/chrome/document.js +++ b/browser/chrome/document.js @@ -1,4 +1,4 @@ -const getDocumentAll = require('@bin/documentAll').getDocumentAll; +const getDocumentAll = require('@/build/Release/documentAll').getDocumentAll; const sdenv = require('sdenv-extend').sdenv(); const window = sdenv.memory.sdWindow; diff --git a/browser/index.js b/browser/index.js index 19a47f5..cc8c42f 100644 --- a/browser/index.js +++ b/browser/index.js @@ -1,4 +1,6 @@ -require('module-alias/register'); +const path = require('path'); +const paths = require('../utils/paths'); +require('module-alias')(path.dirname(paths.package)); // const jsdomDevtoolsFormatter = require('jsdom-devtools-formatter'); // jsdomDevtoolsFormatter.install(); const SdenvExtend = require('sdenv-extend'); diff --git a/package.json b/package.json index c18ab63..08afe27 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sdenv", - "version": "0.1.2", - "description": "", + "version": "0.1.8", + "description": "补环境框架", "main": "main.js", "directories": { "test": "test" @@ -9,8 +9,7 @@ "scripts": { "test": "jest ./test/", "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand ./test/", - "build": "node-gyp rebuild && cp build/Release/documentAll.node ./bin/", - "build:win": "node-gyp rebuild && copy .\\build\\Release\\documentAll.node .\\bin\\", + "install": "node-gyp rebuild", "release": "release-it" }, "logLevel": "debug", diff --git a/test/documentAll.test.js b/test/documentAll.test.js index 9df73c1..011dd2e 100644 --- a/test/documentAll.test.js +++ b/test/documentAll.test.js @@ -1,4 +1,4 @@ -const getDocumentAll = require('../bin/documentAll.node').getDocumentAll; +const getDocumentAll = require('../build/Release/documentAll.node').getDocumentAll; describe('模拟document.all检测', () => { const da = getDocumentAll({ length: 1 });