Created
March 10, 2017 05:42
-
-
Save xiangzhuyuan/3a74f16a7fdad5283a0775c1dc67ab26 to your computer and use it in GitHub Desktop.
Get your local sunrise and sunset time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'uri' | |
require 'nokogiri' | |
require 'byebug' | |
PREFIX= "https://www.google.co.jp/search?q=" | |
QUERY = "+日の出+日の入り" | |
uri = URI.parse("#{PREFIX}#{URI.encode(ARGV[0]+QUERY)}") | |
request = Net::HTTP::Get.new(uri) | |
request["Pragma"] = "no-cache" | |
request["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36" | |
request["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" | |
request["Cache-Control"] = "no-cache" | |
request["Authority"] = "www.google.com" | |
request["Referer"] = "https://www.google.com/" | |
req_options = { | |
use_ssl: uri.scheme == "https", | |
} | |
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| | |
http.request(request) | |
end | |
# response.code | |
# response.body | |
@doc = Nokogiri::HTML(response.body) | |
puts @doc.css("._NId").first.text .strip.split(" ").map(&:strip) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#Usage