回答編集履歴
14
修正
test
CHANGED
@@ -130,12 +130,6 @@
|
|
130
130
|
|
131
131
|
|
132
132
|
|
133
|
-
私の場合はブラウザで質問に書かれたページのソースコードを表示して
|
134
|
-
|
135
|
-
ページ内検索で「February」と検索しても何も見つかりませんでした。
|
136
|
-
|
137
|
-
|
138
|
-
|
139
133
|
私のブラウザなど
|
140
134
|
|
141
135
|
Chrome 59.0.3071.115
|
13
修正
test
CHANGED
@@ -90,6 +90,8 @@
|
|
90
90
|
|
91
91
|
require 'certified'
|
92
92
|
|
93
|
+
require 'date'
|
94
|
+
|
93
95
|
require 'nokogiri'
|
94
96
|
|
95
97
|
|
12
修正
test
CHANGED
@@ -164,7 +164,7 @@
|
|
164
164
|
|
165
165
|
|
166
166
|
|
167
|
-
data =~ /"events":\[{"id":
|
167
|
+
data =~ /"events":\[{"id":\d+,"name":"(.+?)"}\],"/
|
168
168
|
|
169
169
|
|
170
170
|
|
11
修正
test
CHANGED
@@ -168,6 +168,6 @@
|
|
168
168
|
|
169
169
|
|
170
170
|
|
171
|
-
puts $1
|
171
|
+
puts $1 # => TED2016
|
172
172
|
|
173
173
|
```
|
10
修正
test
CHANGED
@@ -154,8 +154,6 @@
|
|
154
154
|
|
155
155
|
require 'certified'
|
156
156
|
|
157
|
-
require 'date'
|
158
|
-
|
159
157
|
|
160
158
|
|
161
159
|
url = 'https://www.ted.com/talks/adam_grant_the_surprising_habits_of_original_thinkers'
|
9
修正
test
CHANGED
@@ -139,3 +139,37 @@
|
|
139
139
|
Chrome 59.0.3071.115
|
140
140
|
|
141
141
|
Windows 10
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
#追記
|
146
|
+
|
147
|
+
```Ruby
|
148
|
+
|
149
|
+
# encoding: utf-8
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
require 'open-uri'
|
154
|
+
|
155
|
+
require 'certified'
|
156
|
+
|
157
|
+
require 'date'
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
url = 'https://www.ted.com/talks/adam_grant_the_surprising_habits_of_original_thinkers'
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
data = open(url, &:read)
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
data =~ /"events":\[{"id":377,"name":"(.+?)"}\],"/
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
puts $1
|
174
|
+
|
175
|
+
```
|
8
修正
test
CHANGED
@@ -102,11 +102,11 @@
|
|
102
102
|
|
103
103
|
|
104
104
|
|
105
|
-
t
|
105
|
+
data = doc.xpath('//script').text
|
106
106
|
|
107
107
|
|
108
108
|
|
109
|
-
t
|
109
|
+
data =~ /"recorded_at":"(.+?)"/
|
110
110
|
|
111
111
|
|
112
112
|
|
7
修正
test
CHANGED
@@ -78,6 +78,48 @@
|
|
78
78
|
|
79
79
|
```
|
80
80
|
|
81
|
+
Nokogiriを使おうとしたバージョン
|
82
|
+
|
83
|
+
```Ruby
|
84
|
+
|
85
|
+
# encoding: utf-8
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
require 'open-uri'
|
90
|
+
|
91
|
+
require 'certified'
|
92
|
+
|
93
|
+
require 'nokogiri'
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
url = 'https://www.ted.com/talks/adam_grant_the_surprising_habits_of_original_thinkers'
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
doc = Nokogiri::HTML.parse(open(url))
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
text = doc.xpath('//script').text
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
text =~ /"recorded_at":"(.+?)"/
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
d = DateTime.parse($1)
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
puts d.strftime('%B %Y') # => February 2016
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
```
|
122
|
+
|
81
123
|
参考にしたページ
|
82
124
|
|
83
125
|
[Rubyで文字列を日時に変換する方法](http://maeharin.hatenablog.com/entry/20120812/p1)
|
6
修正
test
CHANGED
@@ -52,6 +52,8 @@
|
|
52
52
|
|
53
53
|
require 'certified'
|
54
54
|
|
55
|
+
require 'date'
|
56
|
+
|
55
57
|
|
56
58
|
|
57
59
|
url = 'https://www.ted.com/talks/adam_grant_the_surprising_habits_of_original_thinkers'
|
@@ -66,11 +68,21 @@
|
|
66
68
|
|
67
69
|
|
68
70
|
|
71
|
+
d = DateTime.parse($1)
|
72
|
+
|
73
|
+
|
74
|
+
|
69
|
-
p
|
75
|
+
puts d.strftime('%B %Y') # => February 2016
|
70
76
|
|
71
77
|
|
72
78
|
|
73
79
|
```
|
80
|
+
|
81
|
+
参考にしたページ
|
82
|
+
|
83
|
+
[Rubyで文字列を日時に変換する方法](http://maeharin.hatenablog.com/entry/20120812/p1)
|
84
|
+
|
85
|
+
[指定フォーマットで文字列に変換する](http://www.rubylife.jp/ini/date_class/index5.html)
|
74
86
|
|
75
87
|
|
76
88
|
|
5
修正
test
CHANGED
@@ -12,13 +12,19 @@
|
|
12
12
|
|
13
13
|
url = 'https://www.ted.com/talks/adam_grant_the_surprising_habits_of_original_thinkers'
|
14
14
|
|
15
|
+
|
16
|
+
|
15
17
|
data = open(url, &:read)
|
16
|
-
|
17
|
-
date = data.scan(/<meta content=(.+?) itemprop='uploadDate'>/)
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
+
data =~ /<meta content=(.+?) itemprop='uploadDate'>/
|
22
|
+
|
23
|
+
|
24
|
+
|
21
|
-
p
|
25
|
+
p $1 # => 2016-04-01T14:47:47+00:00
|
26
|
+
|
27
|
+
|
22
28
|
|
23
29
|
```
|
24
30
|
|
@@ -56,7 +62,11 @@
|
|
56
62
|
|
57
63
|
|
58
64
|
|
59
|
-
|
65
|
+
data =~ /"recorded_at":"(.+?)"/
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
p $1 # => 2016-02-16T00:00:00.000+00:00
|
60
70
|
|
61
71
|
|
62
72
|
|
4
修正
test
CHANGED
@@ -48,7 +48,7 @@
|
|
48
48
|
|
49
49
|
|
50
50
|
|
51
|
-
url = 'https://www.ted.com/talks/adam_grant_the_surprising_habits_of_original_thinkers
|
51
|
+
url = 'https://www.ted.com/talks/adam_grant_the_surprising_habits_of_original_thinkers'
|
52
52
|
|
53
53
|
|
54
54
|
|
3
修正
test
CHANGED
@@ -61,3 +61,17 @@
|
|
61
61
|
|
62
62
|
|
63
63
|
```
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
私の場合はブラウザで質問に書かれたページのソースコードを表示して
|
68
|
+
|
69
|
+
ページ内検索で「February」と検索しても何も見つかりませんでした。
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
私のブラウザなど
|
74
|
+
|
75
|
+
Chrome 59.0.3071.115
|
76
|
+
|
77
|
+
Windows 10
|
2
修正
test
CHANGED
@@ -31,3 +31,33 @@
|
|
31
31
|
#追記
|
32
32
|
|
33
33
|
勘違いでした。
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
もしかしてこれかもしれません。
|
38
|
+
|
39
|
+
```Ruby
|
40
|
+
|
41
|
+
# encoding: utf-8
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
require 'open-uri'
|
46
|
+
|
47
|
+
require 'certified'
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
url = 'https://www.ted.com/talks/adam_grant_the_surprising_habits_of_original_thinkers/up-next'
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
data = open(url, &:read)
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
puts data.scan(/"recorded_at":"(.+?)"/) # => 2016-02-16T00:00:00.000+00:00
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
```
|
1
修正
test
CHANGED
@@ -25,3 +25,9 @@
|
|
25
25
|
投稿された日付を取り出すなら、より詳しい日付がhtmlに書かれていました。
|
26
26
|
|
27
27
|
ここから、年月をとって、月を英語に直すというのはどうでしょうか。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
#追記
|
32
|
+
|
33
|
+
勘違いでした。
|