var Xray = require('x-ray');
var x = Xray();
var a = false;
var url = "abcdeabcde";
x(url, '.listing_risultati_prodotti .smcc-listing-risultati-prodotto', [{
title: '.first-col a',
link: '.product-description a@href',
prezzo: '.second-col .ish-priceContainer-salePrice'
}])(function(err, obj) {
console.log(obj)
})
查询现在返回两倍相同的值,因为有两个 div 匹配查询。
[ { title: 'aaaa',
link: 'aaaa',
prezzo: 'aaaa' },
{ title: 'bbb',
link: 'bbb',
prezzo: ' bbb' },
{ title: 'ccc',
link: 'ccc',
prezzo: 'ccc' },
.....
....
.....
Then again
{ title: 'aaaa',
link: 'aaaa',
prezzo: 'aaaa' },
{ title: 'bbb',
link: 'bbb',
prezzo: ' bbb' },
{ title: 'ccc',
link: 'ccc',
prezzo: 'ccc' }]
两个 div 具有相同的选择器路径
#maincontent > div.category-section > div.render-category-products.products > div.listing_risultati_prodotti
它们都嵌套在这个 id 中:#smcc_comp_common_wrapper
结构是这样的:
<body>
#smcc_comp_common_wrapper
...
...
#mainwrapper
...
#maincontent > div.category-section > div.render-category-products.products > div.listing_risultati_prodotti
...
#mainwrapper
...
#maincontent > div.category-section > div.render-category-products.products > div.listing_risultati_prodotti
...
...
...
我正在尝试类似的东西:
x(url, '.listing_risultati_prodotti:nth-of-type(1) .smcc-listing-risultati-prodotto',
或者也
x(url, ':nth-match(1 of #mainwrapper) .listing_risultati_prodotti .smcc-listing-risultati-prodotto',
但没有人工作
是否可能仅针对第一类实例?