Created
July 24, 2016 18:17
-
-
Save gouf/15a59a87b7222e718175ed61e13196c8 to your computer and use it in GitHub Desktop.
Mechanize による診断メーカーの情報取得とオストンインゲーム例
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_relative 'shindan_scrape' | |
module Ofuton | |
def self.in(user_name, hide_url: true) | |
result = ShindanScrape.new(362_791, user_name).shindan | |
if hide_url | |
cutoff_last_url(result) | |
else | |
result | |
end | |
end | |
def self.cutoff_last_url(result) | |
result.lines.first(result.lines.size - 1).join | |
end | |
end | |
puts Ofuton.in('gouf') | |
# => | |
# [____] (:3 っ)=≡=-・∴ | |
# goufのオストンチャレンジ! | |
# ↓ | |
# [____] (:3 っ) (失敗:-122cm)床で寝てください | |
# https://shindanmaker.com/362791 |
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 'mechanize' | |
class ShindanScrape | |
SHINDAN_URL = 'https://shindanmaker.com'.freeze | |
def initialize(shindan_id, user_name) | |
@user_name = user_name | |
agent = Mechanize.new | |
@page = agent.get("#{SHINDAN_URL}/#{shindan_id}") | |
end | |
def shindan | |
shindan_result(filled_form) | |
end | |
private | |
def filled_form | |
form = @page.form_with(id: 'form') | |
form.field_with(name: 'u') do |input| | |
input.value = @user_name | |
end | |
form | |
end | |
def shindan_result(filled_form) | |
page = filled_form.submit | |
page.css('#copy_text_140').text | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment