Skip to content

Instantly share code, notes, and snippets.

@rudkovskyi

rudkovskyi/github.rb

Created Feb 27, 2018
Embed
What would you like to do?
require_relative 'request'
require 'nokogiri'
module Requests
class Github < Request
def initialize(url)
super(url)
chrome!
end
def stars_count
Nokogiri::HTML(response.body)
.search(
'.repohead-details-container
li
a.social-count'
).to_a[1].text.strip.tr(',', '.').to_f * 1000
end
private
def chrome!
@request["Accept-Language"] = "en-GB,en-US;q=0.9,en;q=0.8"
@request["Upgrade-Insecure-Requests"] = "1"
@request["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36"
@request["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
@request["Cache-Control"] = "max-age=0"
@request["Connection"] = "keep-alive"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.