1

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

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

如您所见,我正在传递先前在 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')
4

1 回答 1

0

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

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

于 2016-07-18T13:34:54.620 回答