質問編集履歴
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -215,3 +215,73 @@
|
|
215
215
|
end
|
216
216
|
|
217
217
|
```
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
```ruby
|
222
|
+
|
223
|
+
require 'net/http'
|
224
|
+
|
225
|
+
require 'uri'
|
226
|
+
|
227
|
+
puts "検索キーワードを入れてください"
|
228
|
+
|
229
|
+
search_word = STDIN.gets
|
230
|
+
|
231
|
+
uri = URI.parse("https://teratail.com/search?q=#{search_word}")
|
232
|
+
|
233
|
+
http= Net::HTTP.new("teratail.com",443)
|
234
|
+
|
235
|
+
http.use_ssl = true
|
236
|
+
|
237
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
238
|
+
|
239
|
+
response = http.get(uri)
|
240
|
+
|
241
|
+
html_body = response.body
|
242
|
+
|
243
|
+
puts "---ステータスコード---"
|
244
|
+
|
245
|
+
puts response.code
|
246
|
+
|
247
|
+
response.each do |name,value|
|
248
|
+
|
249
|
+
puts name + ":" + value
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
puts "ステータスコード終了"
|
254
|
+
|
255
|
+
File.open("search_html.rb","w") do |io|
|
256
|
+
|
257
|
+
io.write(html_body)
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
puts "マッチングした場所"
|
262
|
+
|
263
|
+
a = []
|
264
|
+
|
265
|
+
File.open("search_html.rb","r",encoding: "UTF-8") do |file|
|
266
|
+
|
267
|
+
file.each_line do |line|
|
268
|
+
|
269
|
+
matching_class = line.match(/"/questions/.{1,9}"/)
|
270
|
+
|
271
|
+
#puts matching_class unless matching_class == nil
|
272
|
+
|
273
|
+
a.push(matching_class) unless matching_class == nil
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
a.each do |b|
|
282
|
+
|
283
|
+
puts b
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
```
|
2
改変
test
CHANGED
File without changes
|
test
CHANGED
@@ -190,7 +190,7 @@
|
|
190
190
|
|
191
191
|
end
|
192
192
|
|
193
|
-
puts "
|
193
|
+
puts "ヘッダー終了"
|
194
194
|
|
195
195
|
File.open("search_html.rb","w") do |io|
|
196
196
|
|
1
訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -192,7 +192,7 @@
|
|
192
192
|
|
193
193
|
puts "ステータスコード終了"
|
194
194
|
|
195
|
-
File.open("cl
|
195
|
+
File.open("search_html.rb","w") do |io|
|
196
196
|
|
197
197
|
io.write(html_body)
|
198
198
|
|
@@ -200,14 +200,18 @@
|
|
200
200
|
|
201
201
|
puts "マッチングした場所"
|
202
202
|
|
203
|
+
matching = nil
|
204
|
+
|
203
|
-
File.open("cl
|
205
|
+
File.open("search_html.rb","r",encoding: "UTF-8") do |file|
|
204
|
-
|
206
|
+
|
205
|
-
file.each_line do |
|
207
|
+
file.each_line do |line|
|
206
|
-
|
208
|
+
|
207
|
-
|
209
|
+
matching_class = line.match(/"/questions/.{1,9}"/)
|
210
|
+
|
208
|
-
|
211
|
+
puts matching_class unless matching_class == nil
|
212
|
+
|
209
|
-
end
|
213
|
+
end
|
210
|
-
|
214
|
+
|
211
|
-
end
|
215
|
+
end
|
212
|
-
|
216
|
+
|
213
|
-
```
|
217
|
+
```
|