我正在Vue中开发一个应用程序,也使用x-ray-scraper
库,但当我尝试在控制台中运行npm run serve
以在本地查看应用程序时,我会收到以下错误:
This dependency was not found:
* _http_common in ./node_modules/http-outgoing/index.js
To install it, you can run: npm install --save _http_common
然后我尝试运行命令npm install --save _http_common
,再次出现错误:
npm ERR! code ETARGET
npm ERR! notarget No matching version found for undefined@_http_common.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
如果没有x-ray-scraper
库,一切都会正常启动,但如果我在项目中包含它,就会出现错误。也许这个错误与版本有关,但我不知道如何修复它。我的package.json
看起来像:
{
"name": "pc-components",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build"
},
"dependencies": {
"axios": "^0.21.0",
"cheerio": "^1.0.0-rc.3",
"core-js": "^3.6.5",
"dns": "^0.2.2",
"phantom": "^6.3.0",
"selenium-webdriver": "^4.0.0-alpha.8",
"vue": "^2.6.11",
"webpage": "^0.3.0",
"x-ray-scraper": "^3.0.6"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"vue-template-compiler": "^2.6.11"
}
}
谢谢你的帮助。
问题与导入语句无关,也与您安装的依赖项无关。
这是我的测试:
- npm初始化到您想要的任何目录中
- npm安装x-ray-scraper
然后:
const x = require("x-ray-scraper");
x('google.com', 'title')
.then((title) => {
console.log(title); // Google
});
// logs Google
您需要一个简单的后端,甚至几行长,以便启动服务并使用包。
你可以在前端、Vue、React等中使用任何你喜欢的东西。
您根本不需要从您已经拥有的内容中获得任何额外的依赖项。
请阅读文档以查看用例