文字列

文字列が含まれているかどうか確認する

str = "ABCDEFG"
res = str.include?("CD")
include?の返り値はbooleanです。
上記の場合、resにはtrueが入ります。

データベース

Mysql2

インストール
gem install mysql2
SELECT文
require 'rubygems'
require 'mysql2'

client = Mysql2::Client.new(:host => "localhost", :username => "root", :database => "dbname")
escaped = client.escape("gi'thu\"bbe\0r's")
results = client.query("SELECT * FROM users WHERE group='#{escaped}'")

スクレイピング

Nokogiri

使い方
$KCODE = "UTF8"

require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'nkf'

page = open("http://funky802.com/noa_data/today_oa.html")
html = Nokogiri::HTML(page.read, nil, 'Shift_JIS')

tr = html.search('//td[@class="basesize"]//table//table/tr')
tr.each_with_index do |a, i|
  puts "title:" +  NKF.nkf('-w', a.xpath('td[2]').inner_text) + " artist:" +  NKF.nkf('-w', a.xpath('td[3]').inner_text)
end

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Menu

メニューサンプル1

メニューサンプル2

開くメニュー

閉じるメニュー

  • アイテム
  • アイテム
  • アイテム
【メニュー編集】

管理人/副管理人のみ編集できます