开发者

nokogiri: invalid xpath?

 lotof开发者_如何学运维xpath = arrayofmanyxpaths.map{|s| "\"" + s + "\""}.join(",")
 puts lotofxpath #=> "/html/body/a[1]", "/html/body/a[2]"

 newb = doc.xpath(lotofxpath).to_a

this will not work, and complain about invalid xpath.

however, copying pasting the output string

 newb = doc.xpath("/html/body/a[1]", "/html/body/a[2]").to_a

will work without problems!!!

what is happening here ?


In the first case you end up calling Nokogiri as follows

newb = doc.xpath("\"/html/body/a[1]\", \"/html/body/a[2]\"").to_a

and this is not the right Ruby syntax to accomplish what you are trying to do. The right way is

newb = doc.xpath(*arrayofmanyxpaths).to_a
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜