Nokogiri and random div name
Question
Using Nokogiri and Ruby.
I have a page to parse with div id's like:
div id="some-list-number^875"
Numbers after ...-number^ changes random, and i just can't do
doc.css('#wikid-list-genres^875').each do |n|
puts n.text.to_s
end
But the base structure is always the same -number^..some digits...
So i need some kind of wildmask for those digits.
How can I deal with that using ruby and Nokogiri?
Thanks!
Solution
You can use ^=
to match the beginning of an attribute, e.g. div[id^=wikid-list-genres]
. (Source: W3C)
However, I noticed that your id attribute has a ^
character in it, which is not allowed in ids, so "wikid-list-genres^875" is not a valid id and will likely cause you problems down the road. (Source: SO) May I suggest changing it to "wikid-list-genres-875" or "wikid-list-genres_875"?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow