Reputation: 4113
Here's an example of the HTML:
<td colspan="3">TARGET</td>
<td>NOT TARGET</td>
How do I use Ruby's Mechanize gem to target only the <td>
with colspan="3"
?
Upvotes: 0
Views: 74
Reputation: 160571
Mechanize relies on the HTML/XML parser Nokogiri to handle its heavy lifting.
Typically we use agent
as the variable for Mechanize. Testing against a local gem server
, this will get an instance of a parsed document, and allow me to extract nodes and their parameters:
page = agent.get('http://0.0.0.0:8808/')
page.at('a')
If I want the text content of that node:
page.at('a').text
# => "abstract"
In your case, use page.at('td[colspan="3"]').text
to get the contents.
Upvotes: 1