Skip to content

Instantly share code, notes, and snippets.

@oNguyenThanhTung
Created August 6, 2018 14:09
Show Gist options
  • Save oNguyenThanhTung/0f629cddad39e4632dc3696d872a556f to your computer and use it in GitHub Desktop.
Save oNguyenThanhTung/0f629cddad39e4632dc3696d872a556f to your computer and use it in GitHub Desktop.
WSM simple json crawler
require 'rest-client'
require 'pry'
require 'nokogiri'
require 'json'
login_form_url = "https://wsm.framgia.vn/en"
login_form_res = RestClient.get(login_form_url)
authenticity_token = Nokogiri::HTML(login_form_res).css("#devise-login-form input[name='authenticity_token']")[1].attributes["value"].value
x_csrf_token = authenticity_token
cookies = login_form_res.cookies
login_url = "https://wsm.framgia.vn/en/users/sign_in"
login_payload = {
"user[email]" => "email",
"user[password]" => "password",
"user[remember_me]" => 0,
"authenticity_token" => authenticity_token,
}
begin
login_res = RestClient.post(login_url, login_payload, {cookies: cookies, x_csrf_token: x_csrf_token})
rescue Exception => e
puts e.class
puts e.inspect
end
signin_cookies = login_res.cookies
timesheet_url = "https://wsm.framgia.vn/en/dashboard/user_timesheets.json"
timesheet_res = RestClient.get(timesheet_url, {cookies: signin_cookies})
puts JSON.parse(timesheet_res.body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment