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
精彩评论