Skip to content

Instantly share code, notes, and snippets.

@paractmol
Created February 27, 2018 21:21
Show Gist options
  • Save paractmol/697bebf5eca29ffd51249fb5a9064f15 to your computer and use it in GitHub Desktop.
Save paractmol/697bebf5eca29ffd51249fb5a9064f15 to your computer and use it in GitHub Desktop.
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