使用相同的classNameselect多个标签?

使用这个语法:

x('http://www.viadeo.com/fr/company/unicef', '.page-content', [{ img:'img@src', bio:'.pan-desc-description', org:'.pan-desc-footer-element @element-value', link: '.element-value a@href', **twitter:'.element-value a@href'** // I get the previous link not the twitter one }]).write('result.json') 

网站内有多个具有该特定类名的项目,但只返回第一个。 有没有办法抓住他们所有人,也许我可以做一个限制与回报? 我很抱歉,如果它在文档中,我已经读了两遍,它看起来像没有明确说的任何地方。

您可以利用铬检查器工具来获取适当的select器,

在这里,这个代码为我工作,

 var Xray = require('x-ray'); var x = Xray(); x('http://www.viadeo.com/fr/company/unicef', '.page-content', [{ img:'img@src', bio:'.pan-desc-description', org:'.pan-desc-footer-element @element-value', link: '.element-value a@href', twitter:'.mbs:nth-child(4) a@href' // or use div.element-value.gu.gu-last a@href }]).write('result.json') 

在那里,我们得到这个结果。

 [ { "img": "http://static8.viadeo-static.com/fzv6VNzGukb7mt5oV0Nl-wQxCDI=/fit-in/200x200/filters:fill(white)/7766b960b98f4e85affdab7ffa9863c7/1434471183.jpeg", "bio": "Le Fonds des Nations unies pour l'enfance (abrégé en UNICEF ou Unicef pour United Nations International Children's Emergency Fund en anglais) est une agence de l'ONU consacrée à l'amélioration et à la promotion de la condition des enfants. Son nom était originellement United Nations International Children's Emergency Fund, dont elle a conservé l'acronyme. Elle a activement participé à la rédaction, la conception et la promotion de la convention relative aux droits de l'enfant (CIDE), adoptée suite au sommet de New York en 1989. Son revenu total en 2006 a été de 2 781 millions Dollar US.\r\n L'UNICEF a reçu le prix Nobel de la paix en 1965.", "link": "http://www.unicef.org/", "twitter": "http://www.twitter.com/UNICEF " } ] 

这里是你如何得到一个合适的铬select器:

首先你右键单击并单击检查。 在这里输入图像说明

然后你点击复制select器,并使用它。 在这里输入图像说明

当你复制select器时,它会说,

 #pan-desc > div.pan-desc-grey > div > div:nth-child(4) > div.element-value.gu.gu-last > a 

您可以直接使用它,或者改进它。

你只需要用括号来包装你想要的“拆分”。

这里是代码为我工作。

 var Xray = require('x-ray'); var x = Xray(); x('http://www.viadeo.com/fr/company/unicef', '.page-content', { img:'img@src', bio:'.pan-desc-description', org:'.pan-desc-footer-element @element-value', link: ['.element-value a@href'], //twitter:'.element-value a@href' }) (function(err, title) { console.log(title) }); 

我还删除了外括号,因为页面内容永远不会有多个元素,所以你永远不会想要多个元素。