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"?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Mechanize relies on the HTML/XML parser Nokogiri to handle its heavy lifting.
Typically we use
agentas the variable for Mechanize. Testing against a localgem server, this will get an instance of a parsed document, and allow me to extract nodes and their parameters:If I want the text content of that node:
In your case, use
page.at('td[colspan="3"]').textto get the contents.