Hi folks,
The code below almost works perfect. Thus it creates the text files with
the
right content. However, the name of the text file should correspond to
the
Bugtraq ID. As of now it’s Bugtraq ID 1 and 3.txt, 2-2, and Bugtraq ID 3
1.txt. What do I have to correct? Is it index - 1?
Thanks,
Tom
Initialize Logger
require ‘logger’
root_logger = Logger.new ‘root.log’
root_logger.level = Logger::INFO
Setup at_exit hook
at_exit { root_logger.info ‘done.’ }
%w{ rubygems hpricot open-uri }.each { |lib| require lib }
URL_MASK =
‘http://www.securityfocus.com/bid/%i’.freezehttp://www.securityfocus.com/bid/%i’.freeze
tgroup = ThreadGroup.new
root_logger.info ‘Parsing SecurityFocus…’
( 1 … 3 ).each do |id|
root_logger.info " open #{ URL_MASK % id }"
thread = Thread.new do
begin
Hpricot open( URL_MASK % id )
rescue => error
root_logger.error error.inspect
end
end
tgroup.add thread
end
tgroup.list.each_with_index do |thread, index|
if doc = thread.value
File.open( “#{ index + 1 }.txt”, ‘w+’ ) do |file|
file << ( doc/‘#vulnerability’ ).inner_text
end
end
end