I have the following HTML
<div id="profile-bio-full">
<p>Bla bla bla bla </p>
<p>Site: <a href="http://www.something.com" rel="nofollow">something.com</a></p>
<p>Facebook: <a href="http://www.facebook.com" rel="nofollow">facebook.com</a></p>
<p>Twitter: <a href="http://www.twitter.com" rel="nofollow">www.twitter.com</a></p>
</div>
And i need to get the Twitter URL (the href “a” property).
I’m using Rails with Nokogiri gem, and using Nokogiri xPath funciton.
I’m using this xPath
//div[contains(@id, "profile-bio-full")]/a[contains(@href, "twitter.com")]
But don’t work 🙁 . Any guesses?
Your single forward slash before your
amatcher specifies that theaelement needs to be an immediate child ofdiv— but it’s not, it’s a child ofp.You can either do this:
Or you can just change
/ato//ato mean theajust has to be a descendant rather than an immediate child.