-
Notifications
You must be signed in to change notification settings - Fork 0
/
suisenmerge.rb
executable file
·75 lines (67 loc) · 1.9 KB
/
suisenmerge.rb
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/ruby -Ku
# リンクを正しいものに差し替えたい
# マッチングされなかった枠のあまりをまとめて表示したい
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'nkf'
list = Hpricot(open('show_list.html').read)
waku = Hpricot(open('recruit2009-suisen-jokyo.html').read)
#list = Hpricot(
# NKF.nkf('-w', open('http://www.agusa.nuie.nagoya-u.ac.jp/job10/show_list.php').read)
#)
#waku = Hpricot(
# NKF.nkf('-w', open('http://133.6.202.192:8080/recruit2009/recruit2009-suisen-jokyo.jsp').read)
#)
free = Hpricot::Elements.new
(list/:tr).each do |row|
if row.containers.length == 9
if row.containers[0].name == "th"
row.containers[1].after('<th>可否</th>')
row.containers[2].after('<th>残枠</th>')
next
elsif row.containers[3].inner_text == '自由'
free.push(row)
next
end
name = row.containers[1].inner_text
row.containers[1].inner_html = "<a href=\"http://www.google.com/search?hl=ja&q=#{name}&lr=lang_ja\" target=\"_blank\">#{name}</a>"
$matched = Array.new()
i = 0
(waku/:tr).each do |comp|
if comp.containers[0].name == 'th'
i += 1
next
elsif comp.containers[0].inner_text != name
i += 1
next
end
$matched[i] = true
kahi = comp.containers[1]
nokori = comp.containers[2]
children = row.containers
children.insert(2,kahi)
children.insert(3,nokori)
row.children = children
i += 1
end
end
end
free.remove
unmatchedtable = Hpricot(
'<table border="1">
<tbody>
<tr>
<th>社名</th>
<th>可否</th>
<th>残枠</th>
</tr>
</tbody>
</table>')
for i in 0...(waku/:tr).length do
if $matched[i] != true
unmatchedtable.search('/table/tbody/tr').after( (waku/:tr)[i].html )
end
end
list.search('/table').after(unmatchedtable.html)
print list.to_html