Skip to content

Instantly share code, notes, and snippets.

@choipd
Created October 5, 2012 16:49
Show Gist options
  • Save choipd/3840933 to your computer and use it in GitHub Desktop.
Save choipd/3840933 to your computer and use it in GitHub Desktop.
Nokogiri 사용법
uri = "http://www.mulga.go.kr/price/bestStore/regionInfo.do?bestStoreSeq=#{n}"
doc = Nokogiri::HTML(open(uri))
data = GoodShop.new
data.crawl_no = n
data.title = doc.xpath("//div[attribute::id='content']/h4").text
data.address = doc.xpath("//th[text()='주소']/following-sibling::*").text
data.phone = doc.xpath("//th[text()='전화번호']/following-sibling::*").text
data.business_type = doc.xpath("//th[text()='업종']/following-sibling::*").text
a = doc.xpath("//th[text()='주요품목']/following-sibling::*").collect { |a| a.text }
h = Hash[*a]
data.items = h
data.remark = doc.xpath("//h5[text()='업소자랑거리']/following-sibling::*").text
data.save!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment