MMonitor

TODO: Write a gem description

Installation

Add this line to your application's Gemfile:

gem 'mmonitor'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mmonitor

Usage

TODO: Write usage instructions here

# -*- encoding: utf-8 -*-
require 'mmonitor'
items = {}
url = 'http://loreal.tmall.com/category.htm?search=y&scene=taobao_shop'
a = MMonitor::Crawler.new(url)
items.merge!(a.items)

url = 'http://www.amazon.cn/s/ref=sr_nr_p_89_0?rh=i%3Aaps%2Ck%3A%E5%B7%B4%E9%BB%8E%E6%AC%A7%E8%8E%B1%E9%9B%85%2Cp_89%3AL%27Oreal+Paris+%E5%B7%B4%E9%BB%8E%E6%AC%A7%E8%8E%B1%E9%9B%85&keywords=%E5%B7%B4%E9%BB%8E%E6%AC%A7%E8%8E%B1%E9%9B%85&ie=UTF8&qid=1397212889&rnid=125596071'
b = MMonitor::Crawler.new(url)
items.merge!(b.items)

url = 'http://search.jd.com/search?keyword=%E7%BE%8E%E5%AE%9D%E8%8E%B2&enc=utf-8&qr=&qrst=UNEXPAND&et=&rt=1&stop=1&area=1&wtype=1&ev=exbrand_%E7%BE%8E%E5%AE%9D%E8%8E%B2%EF%BC%88MAYBELLINE%EF%BC%89%40&uc=0#select'
c = MMonitor::Crawler.new(url)
items.merge!(c.items)

url = 'http://search.jumei.com/?filter=0-11-1&search=%E6%AC%A7%E8%8E%B1%E9%9B%85&from=search_topbar_%E6%AC%A7%E8%8E%B1%E9%9B%85_word_pos1&cat=&bid=1'
d = MMonitor::Crawler.new(url)
items.merge!(d.items)

url = 'http://search.lefeng.com/search/search?key=%E6%AC%A7%E8%8E%B1%E9%9B%85&wt.s_pg=Isearch&wt.s_pf=public'
e = MMonitor::Crawler.new(url)
items.merge!(e.items)

url = 'http://search.suning.com/%E5%B7%B4%E9%BB%8E%E6%AC%A7%E8%8E%B1%E9%9B%85/cityId=9264&iy=-1&ct=1&si=5&st=0'
f = MMonitor::Crawler.new(url)
items.merge!(f.items)

url = 'http://www.yhd.com/ctg/s2/c0-0/b/a-s1-v0-p1-price-d0-f06-m1-rt0-pid-mid0-k%E6%AC%A7%E8%8E%B1%E9%9B%85/'
j = MMonitor::Crawler.new(url)
items.merge!(j.items)

url = 'http://searchex.yixun.com/html?key=%E6%AC%A7%E8%8E%B1%E9%9B%85&area=1&sort=0&show=0&size=40&pf=1&as=1&charset=utf-8&YTAG=1.100000401#list'
h = MMonitor::Crawler.new(url)
items.merge!(h.items)

require 'csv'
header_row = ['平台ID',  'SKU ID','商品名称',  '平台',  '原价',  '销售价',  '商品图片', '价格图片', '抓取日期']
CSV.open('测试数据.csv', "wb:GB18030", col_sep: ',') do |csv|
  csv << header_row
  items.each do |item_id, item|
    csv << [
      item_id,
      item[:sku_id],
      item[:title],
      item[:provider],
      item[:tag_price],
      item[:price],
      item[:photo_url],
      item[:price_url],
      Time.now.to_date.to_s
    ]
  end
end