Skip to content

Instantly share code, notes, and snippets.

@nkwsy

nkwsy/search.rb Secret

Created December 27, 2015 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkwsy/30ae6ea95119eb8ed1a4 to your computer and use it in GitHub Desktop.
Save nkwsy/30ae6ea95119eb8ed1a4 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'nokogiri'
require 'csv'
require 'Mechanize'
require 'open-uri'
#require 'open-uri'
agent = Mechanize.new
agent.user_agent_alias = 'Mac Safari'
page = agent.get('https://relivent.web.page')
ticket_form = page.form('enterTicketsForm')
ticket_form.ticket1 = 9189531900
ticket_form.ticket2 = 9189531901
page = agent.submit(ticket_form)
doc = Nokogiri::HTML(page)
csv = CSV.open("xtick.csv", 'w',{:col_sep => ",", :quote_char => '\'', :force_quotes => false, :skip_blanks => true, skip_lines: /^(?:,\s*)+$/})
doc.xpath('//table/tbody/tr').each do |row|
tarray = []
row.xpath('td[@class="bodytextsmall"]').each do |cell|
tarray << cells.text.strip
end
puts tarray
csv << tarray
end
csv.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment