Search code examples
htmlrubyparsinghpricot

Get div attributes via Hpricot


I've got a specific div id called progress_bar ()

And I'm trying to retrieve just the width of the div. I'm fairly new to Ruby and Hpricot so any help would be greatly appreciated.

Cheers, Scott


Solution

  • As long as the width attribute is set in the HTML something like this should work according to the docs:

    doc = Hpricot("my html")
    (doc/"#progress_bar")['width']
    

    Found here: https://github.com/hpricot/hpricot