1 require 'nokogiri'
2 require 'open-uri'
3 require "iconv"
4
5 task :dreamtype => :environment do
6 # doc = Nokogiri::HTML(File.open("a.html"))
7 # doc.css("table.txt>tr>td:nth-child(1)").each do |link|
8 # Dream.create(:url => "a",:name => link.content)
9 # end
10 # da = Iconv.iconv("UTF-8","GB2312",Nokogiri::HTML(open(url)))
11 ic = Iconv.new("utf-8//IGNORE","gb2312//IGNORE")
12 doc = Nokogiri::HTML(File.open("a.html"))
13 doc.css("table.txt>tr:nth-child(8)>td:nth-child(2)>a").each do |k|
14 url = "http://www.tongcha.com/"+k[:href]
15 da = Nokogiri::HTML(open(url))
16 da.css("table.txt>tr:nth-child(1)>td").each do |c|
17 #puts c.content
18 DayDream.create(:dream_id => 8,:name => k.content,:content => c.content)
19 end
20 puts url
21 end
22 end

 

相关文章:

  • 2021-12-31
  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2021-09-09
  • 2021-06-17
猜你喜欢
  • 2021-08-11
  • 2021-05-22
  • 2021-08-11
  • 2021-08-06
相关资源
相似解决方案