forked from tokihiro000/Crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresReg.rb
64 lines (53 loc) · 1.13 KB
/
resReg.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
# -*- coding: utf-8 -*-
require "net/http"
require "uri"
ImgTag = Array.new
LinkTag = Array.new
ImgArray = Array.new
LinkArray = Array.new
uri = URI.parse("http://news4vip.livedoor.biz/");
#uri = URI.parse("http://livedoor.4.blogimg.jp/news4vip2/imgs/9/6/96a36e43.jpg")
Net::HTTP.start(uri.host, uri.port){|http|
#ヘッダー部
header = {
"user-agent" => "Ruby/#{RUBY_VERSION} MyHttpClient"
}
#ボディ部
body = "id=1&name=name"
#送信
response = http.post(uri.path, body, header)
p response
#p response['location']
# p response.body
#
# imgタグとaタグのみをレスポンスデータから抽出する
#
reImg = /<img.*?>/
res = response.body
res.gsub(reImg) do |matched|
ImgTag << matched
end
reA = /<a.*?>/
res.gsub(reA) do |matched|
LinkTag << matched
end
}
http_img = /http:.*?(jpg|gif|png)/
ImgTag.each do |image|
if image =~ http_img
ImgArray << $&
end
end
http_link = /http:.*?\"/
LinkTag.each do |link|
if link =~ http_link
tmp = $&
LinkArray << tmp.delete!("\"")
end
end
ImgArray.each do |image|
puts image
end
LinkArray.each do |link|
puts link
end