I’m using Nokogiri for a simple example to get council tax bands for a postcode (http://www.voa.gov.uk/cti/InitS.asp?lcn=0)
Here is the code I have at the moment:
a = Mechanize.new{ |agent| agent.user_agent_alias = 'Mac Safari'}
a.get('http://www.voa.gov.uk/cti/InitS.asp?lcn=0') do |page|
form = page.form_with(:id => "frmInitSForm")
form.txtPostCode = "NN15 6UA"
page = a.submit form
page.search("tr").each do |tr|
textF = tr.text.strip
textF.gsub!(/[\n]+/, "\n")
puts textF
end
end
end
At the moment this prints out all text inside the tr
I then need inside the do something similar to
tdFirst = tr.children("td:first").text
tdSecond = tr.children("td:nth-child(2)").text
How do I get the first and second td?
In your inner block, try