我在循环中有这个 Xpath 查询,
//div[@class='listing_content'][#{i}]/div/div/h3/a/text()
我想单独处理每个节点
问题是它提供了正确的节点,但同时所有这些节点。
还有什么时候i > 1
,它什么也不返回?
for i in (1...30)
name = page.xpath("//div[@class='listing_content'][#{i}]/div/div/h3/a/text()")
puts "this is name"
puts name
#Get Business phone
phone = page.xpath("//div[@class='listing_content'][#{i}]//span[@class='business-phone phone']/text()")
puts "this is phone"
puts phone
#Get Business website(if any)
puts "this is website"
website = page.xpath("//div[@class='listing_content'][#{i}]//li[@class='website-feature']//@href")
puts website
end