I'm trying to get the text between two elements in nokogiri and pair the data with the text in the element in front of it.
html =
"<website>
<maindeck>
1<card>Blood Crypt</card>
2<card>Temple Garden</card>
</maindeck>
<maindeck>
3<card>Angel of Serenity</card>
4<card>Forest</card>
</maindeck>
</website>"
I want to end up with an array like this
#=> [[1,"Blood Crypt"],[2,"Temple Garden"]]
A previous example provided this as an answer, but I'm unsure of what it does/ how to use it.
/*/div[1]/following-sibling::text()[1]
Original link : grabbing text between two elements in nokogiri?
This works:
doc = Nokogiri::HTML(html)
doc.xpath('//maindeck[1]/text()').map { |n| [n.text.to_i, n.next.text] }
#=> [[1, "Blood Crypt"], [2, "Temple Garden"]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With