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-ray中,而不是将其指向远程URL?
答案 0 :(得分:0)
This example解决了我的问题。只需传递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);
});