关键词:
# coding: utf-8
require 'nokogiri'
require 'mongo'
require 'open-uri'
require 'pp'
def extract_threads
l = open('http://hayabusa3.2ch.net/appli/subback.html').read.force_encoding('cp932').encode('utf-8')
n = Nokogiri::HTML.parse(l)
n.css('#trad a').select |node| node.children[0].to_s =~ /.*スレ/ .map |node| node['href'].split('/')[0].to_i
end
def extract_posts(thread_id, from)
l = open("http://hayabusa3.2ch.net/test/read.cgi/appli/#thread_id/#from-").read.force_encoding('cp932').encode('utf-8', invalid: :replace, undef: :replace)
n = Nokogiri::HTML.parse(l)
n.css('.thread dd').map do |dd|
dt = dd.previous
match_data = dt.to_s.match(/<dt>(\d*).*(\d4)\/(\d2)\/(\d2).*(\d2):(\d2):(\d2)/)
if match_data
post_id, year, month, day, hour, minute, second = match_data.captures.map(&:to_i)
if post_id > 1
body = dd.to_s.gsub(/<\/?dd>/, '').gsub("\n", '').split('<br>')
thread_id: thread_id, post_id: post_id, posted_at: Time.local(year, month, day, hour, minute, second), body: body
else
nil
end
else
nil
end
end.compact
end
while true do
begin
puts "#Time.now crawling..."
hogehoge = Mongo::Connection.new.db("hogehoge")
posts = hogehoge.collection("posts")
thread_ids = extract_threads
lasts = extract_threads.map do |thread_id|
posts.
find(thread_id: thread_id).
map |post| post['post_id'] .max || 0
end
thread_ids.zip(lasts).each do |thread_id, last|
next if last >= 1000
puts "extracting post thread:#thread_id, range:#last + 1-"
extracted_posts = extract_posts(thread_id, last + 1)
puts "got #extracted_posts.size posts"
extracted_posts.each |post| posts.insert post
end
rescue => e
puts e.message
end
sleep 300
end
ruby履带式(代码片段)
查看详情
textcraigslist履带式起重机(代码片段)
查看详情
actionscript3as3履带式装载机进展(代码片段)
查看详情
履带式与刮板式
】履带式与刮板式【英文标题】:crawlervsscraper【发布时间】:2011-03-1313:17:20【问题描述】:有人可以根据范围和功能区分爬虫和抓取工具吗?【问题讨论】:这些术语没有精确的定义。有使用示例吗?我想编写一个应用程序,... 查看详情
徐工挖掘机270是啥发动机型号
...考技术A设备型号XE270DK机型简称270挖机吨位(t)26.4行走方式履带式铲斗形式反铲工况用途通用型发动机系统型号QSB7型式4冲程、直喷、水冷、涡轮增压、空空中冷额定功率(kW)150额定转速(r/min)2050最大扭矩(N·m)825总排量(L)6.7气缸数(个... 查看详情
somebot机械臂智能坦克车应该这样玩儿!(代码片段)
...进阶玩法,把机械臂安装到一个智能坦克车上,履带式坦克车拥有超强的越野能力,双侧双电机驱动又使其具有灵活的机动性,两者叠加之后俨然就是一架军警排爆车啊! 查看详情
somebot机械臂智能坦克车应该这样玩儿!(代码片段)
...进阶玩法,把机械臂安装到一个智能坦克车上,履带式坦克车拥有超强的越野能力,双侧双电机驱动又使其具有灵活的机动性,两者叠加之后俨然就是一架军警排爆车啊! 查看详情
动作捕捉技术在四足机器人研究中的应用
轮式/履带式移动机器人可以胜任很多场景的探索、运输的任务,但是随着应用空间的拓展,需要机器人在山地、峭壁、丛林、雪地等崎岖复杂的地形的任务也逐渐增多,轮式/履带式机器人难以在这类地形中移动。自然界中动物... 查看详情
markdowngit代码片段(代码片段)
查看详情
csharp代码片段(代码片段)
查看详情
javascript代码片段(代码片段)
查看详情
textvisualbasic代码片段(代码片段)
查看详情
sqloracle代码片段(代码片段)
查看详情
swift代码片段(代码片段)
查看详情
java代码片段【安卓】(代码片段)
查看详情
shbash的代码片段(代码片段)
查看详情
markdownphpexcelnotes和代码片段(代码片段)
查看详情
javaandroid的代码片段(代码片段)
查看详情