X射线:从文件中读取HTML,而不是一个URL
问题描述:
代码
const Xray = require('x-ray');
const xray = Xray();
// How do I read a file, rather than a URL?
const url = 'https://www.tel-o-fun.ga/';
xray(url, '.marker')((err, value) => {
console.log(value);
});
我的目标
我使用X射线刮从网站上的一些日期。出于测试和开发的目的,我想从本地文件解析数据而不是远程资源。X射线:从文件中读取HTML,而不是一个URL
如何加载本地文件到的X射线,而不是将其指向远程URL?
答
This example从X射线回购解决我的问题。只需通过一个HTML字符串而不是URL:
const path = require('path');
const Xray = require('x-ray');
const read = require('fs').readFileSync;
const html = read(path.resolve(__dirname, 'index.html'));
const xray = Xray();
xray(html, '.marker')((err, value) => {
console.log(value);
});