Here is the code I'm using:
location = block.xpath("*/img")
puts location
And this outputs:
<img src="/images/p.gif" height="1" width="0">
What I want to do is get the width attribute out of the html, but I can't seem to get that too work. I think I need to put ['width']
somewhere in my code, and I've tried following various examples online but couldn't get it to work.
CSS selectors tend to be easier and more readable:
puts block.at('img')[:height]
Take a look at the xpath syntax from this XPath Tutorial.
Try block.at_xpath("*/img")["width"]
, or */img/@width
if there is just one element.
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