ruby - Regex to select id -
is there way utilize regex or "like" function when don't have exact element id, know general format?
currently have
doc.css('table[id="uta_basic"]//tbody')
but i'd find table id xyz_basic
, or table _basic
work.
i'd open switching xpath if needed.
you can utilize xpath function contains
check if id attribute contains substring "_basic":
doc.xpath('//table[contains(@id, "_basic")]/tbody')
note:
however way may give false positive if, example, exists in document table tags ids _basical
_basic_1
since function doesn't check position or characters after, presence of substring.
if need precise, can solve problem emulating xpath 2.0 function ends-with
this:
doc.xpath('//table[substring(@id,string-length(@id)-string-length("_basic")+1)="_basic")]/tbody')
ruby regex nokogiri
No comments:
Post a Comment