-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadPosters.rb
More file actions
44 lines (34 loc) · 838 Bytes
/
ThreadPosters.rb
File metadata and controls
44 lines (34 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'nokogiri'
require 'rubygems'
require 'rest_client'
require 'sqlite3'
db = SQLite3::Database.new("test.db")
class ThreadPosters
def initialize(url, db)
@url = url
@db = db
end
def create_table
@db.transaction
@db.execute("create table posters (id INTEGER PRIMARY KEY, name TEXT);")
@db.commit
end
def save_posters
doc = Nokogiri::HTML(RestClient.get(@url))
names = doc.css('div[class = "username_container"] strong')
@db.transaction
names.each do |name|
input = name.text
@db.execute("insert into posters (name) values (?)", input)
end
@db.commit
end
attr_reader :url, :db
attr_writer :url, :db
end
def test(database)
tp = ThreadPosters.new("http://forum.bodybuilding.com/showthread.php?t=139556973", database)
tp.create_table
tp.save_posters
end
test(db)