質問編集履歴
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,6 +52,48 @@
|
|
52
52
|
|
53
53
|
```
|
54
54
|
|
55
|
+
|
56
|
+
|
57
|
+
def scraping(keyword)
|
58
|
+
|
59
|
+
submit_keyword(keyword)
|
60
|
+
|
61
|
+
@agent.page.search('div.g').map do |node|
|
62
|
+
|
63
|
+
title = node.search('a')
|
64
|
+
|
65
|
+
next if title.empty?
|
66
|
+
|
67
|
+
query = URI.decode_www_form(URI(title.attr("href")).query)
|
68
|
+
|
69
|
+
url = query[0][1]
|
70
|
+
|
71
|
+
snipped = node.search('div.s > span.st')
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
next if snipped.empty? || snipped.children.empty?
|
76
|
+
|
77
|
+
{
|
78
|
+
|
79
|
+
url: url,
|
80
|
+
|
81
|
+
title: expect_tag(title.children.to_html),
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
end.reject do |list|
|
88
|
+
|
89
|
+
list.nil?
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
55
97
|
query = URI.decode_www_form(URI(title.attr("href")).query)
|
56
98
|
|
57
99
|
|
@@ -72,6 +114,16 @@
|
|
72
114
|
|
73
115
|
end
|
74
116
|
|
117
|
+
|
118
|
+
|
119
|
+
def expect_tag(string)
|
120
|
+
|
121
|
+
string.gsub(/(<b>|</b>|<br>|</br>|\R)/, '')
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
75
127
|
```
|
76
128
|
|
77
129
|
|