Skip to content

Instantly share code, notes, and snippets.

@LitvinenkoD89
Created August 15, 2017 13:14
Show Gist options
  • Save LitvinenkoD89/60edfbedfc8852cd22baeca337728755 to your computer and use it in GitHub Desktop.
Save LitvinenkoD89/60edfbedfc8852cd22baeca337728755 to your computer and use it in GitHub Desktop.
ucaoa_console_test
url = "http://www.ucaoa.org/searchserver/people.aspx?id=AA614225-2260-4578-9513-18089A0F8951&cdbid=&canconnect=0&canmessage=0&map=False&toggle=True&hhSearchTerms="
t = Typhoeus.get url
page = Nokogiri::HTML t.body
links = []
pagination = (2..10).to_a
pagination.each do |page_num|
body = page.at('#SearchResultsForm').search('input').inject({}){|acc,c| acc[c.attr('name')] = c.attr('value'); acc}
act = page.at('#SearchResultsForm').attr('action')
act = act[2..act.length]
action = URI.join("http://www.ucaoa.org/searchserver/", act).to_s
param_name = page_num.to_i > 9 ? "SearchResultsGrid$ctl29$ctl#{page_num.to_s}" : "SearchResultsGrid$ctl29$ctl0#{page_num.to_s}"
body['__EVENTTARGET'] = param_name
body['__EVENTARGUMENT'] = ""
headers = {
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Cookie' => 'ASP.NET_SessionId=nfdzr1y3s3oe2hgb0uumd30y; ymssc=search_rsss06; ASPSession=Owner=C; ASPSESSIONIDAARRTQRA=JIBOOPDBAGEHKKMPNFIBDMNL; apvc=saas749',
'Upgrade-Insecure-Requests' => '1',
'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
}
params = {
method: :post,
page_type: 'search',
body: body.inject([]){|acc,c| acc+["#{CGI.escape(c[0])}=#{CGI.escape(c[1].to_s)}"]}.join('&')
body: body
}
t_2 = Typhoeus.get action, headers: headers, body: params
page_2 = Nokogiri::HTML t_2.body
page_2.search('a').each do |a|
if a.attr('href').include? '/members/?id='
links.push(a.attr('href'))
end
end
end
links.uniq.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment