【问题标题】:Scrape web with x-ray用 X 射线刮网
【发布时间】:2016-06-01 23:57:17
【问题描述】:

我正在使用 X 射线从网站中提取一些数据,但是当我使用内置功能爬到另一个页面时,它根本不起作用。

UnitPrice 是我要提取的参数,但我总是得到“undefined”。

如您所见,我正在传递先前在 url 属性上提取的 href 值。

var Xray = require('x-ray');
var x = Xray();
var x = Xray({
  filters: {
    cleanPrice: function (value) {
      return typeof value === 'string' ? value.replace(/\r|\t|\n|€/g, "").trim() : value
    },
    whiteSpaces: function (value) {
      return typeof value === 'string' ? value.replace(/ +/g, ' ').trim() : value
    }
  }
});

x('https://www.simply.es/compra-online/aceite-vinagre-y-sal.html',
  '#content > ul',
  [{
    name: '.descripcionProducto | whiteSpaces',
    categoryId: 'input[name="idCategoria"]@value',
    productId: 'input[name="idProducto"]@value',
    url: 'li a@href',
    price: 'span | cleanPrice',
    image: '.miniaturaProducto@src',
    unitPrice: x('li a@href', '.precioKilo')
  }])
  .paginate('.link@href')
  .limit(1)
  // .delay(500, 1000)
  // .throttle(2, 1000)
  .write('results.json')

【问题讨论】:

  • 如果网络上几乎没有教程并且文档真的很差,我无法理解为什么这个库有这么多星。
  • 我认为文档不是最新的,但图书馆仍有潜力

标签: node.js web-crawler x-ray


【解决方案1】:

有一个拉取请求来解决这个问题。同时您可以使用只需一行代码的解决方案。看到这个:

https://github.com/lapwinglabs/x-ray/pull/181

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多