質問編集履歴

3

誤字

2016/11/11 05:43

投稿

shigahi
shigahi

スコア21

test CHANGED
File without changes
test CHANGED
@@ -46,9 +46,9 @@
46
46
 
47
47
  doc = Nokogiri::HTML.parse(html, nil, charset)
48
48
 
49
- doc.xpath('//tr[@class="day13"]/td[@class="pressureMin"]')
49
+ doc.xpath('//tr[@class="day13"]/td[@class="pressureMin"]').text
50
-
50
+
51
- puts doc.xpath('//tr[@class="day13"]/td[@class="pressureMin"]')
51
+ puts doc.xpath('//tr[@class="day13"]/td[@class="pressureMin"]').text
52
52
 
53
53
  end
54
54
 

2

プログラムの追加

2016/11/11 05:43

投稿

shigahi
shigahi

スコア21

test CHANGED
File without changes
test CHANGED
@@ -4,11 +4,55 @@
4
4
 
5
5
  ###該当のソースコード
6
6
 
7
+ ```ruby
8
+
9
+ #!/usr/bin/ruby
10
+
11
+ require 'mechanize'
12
+
13
+ agent = Mechanize.new
14
+
15
+ agent.user_agent_alias = 'Windows Mozilla'
16
+
17
+ url = 'https://www.watashi-move.jp/wl/mydata/sphygmomanometer.php?targetDate=2016/07/01'
18
+
19
+ page = agent.get(url)
20
+
21
+ mypage = page.form_with(id: 'form1') do |form|
22
+
23
+ form.loginid = '*'
24
+
25
+ form.password = '*'
26
+
27
+ end.submit
28
+
29
+
30
+
31
+ require 'nokogiri'
32
+
33
+ require 'open-uri'
34
+
35
+ url = 'https://www.watashi-move.jp/wl/mydata/sphygmomanometer.php?targetDate=2016/07/01'
36
+
37
+ user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36'
38
+
39
+ charset = nil
40
+
41
+ html = open(url, "User-Agent" => user_agent) do |f|
42
+
43
+ charset = f.charset
44
+
45
+ f.read
46
+
7
47
  doc = Nokogiri::HTML.parse(html, nil, charset)
8
48
 
9
- doc.xpath('//*div/div/div/div/div/div[@class="datas"]/tr[@id="lidtTr13"]/td[@class="pressureMin"]/span')
49
+ doc.xpath('//tr[@class="day13"]/td[@class="pressureMin"]')
10
-
50
+
11
- puts doc.xpath('//*div/div/div/div/div/div[@class="datas"]/tr[@id="listTr13"]/td[@class="pressureMin"]/span')end
51
+ puts doc.xpath('//tr[@class="day13"]/td[@class="pressureMin"]')
52
+
53
+ end
54
+
55
+ ```
12
56
 
13
57
  ###試したこと
14
58
 

1

htmlの追加

2016/11/11 05:42

投稿

shigahi
shigahi

スコア21

test CHANGED
File without changes
test CHANGED
@@ -1,105 +1,185 @@
1
1
  #実現したいこと
2
2
 
3
- webページの数値が記載された表から、nokogiriを使って数値を抽出しようとしているのですが実行するとNaNとだけ出力されてしまいます。
3
+ nokogiriを使って数値を抽出しようとしているのですが実行するとNaNとだけ出力されてしまいます。Webページは血圧計の結果を送ると表に記録されます。13日の値を取り出そうとしています
4
-
5
- Webページはオムロンのウェルネスリンクというところの、血圧測定器の結果を送ると、
6
-
7
- ![イメージ説明](5bd8e508ea454f0c61965e5be29d69ae.png)
8
-
9
- このような表に記録されます。
10
-
11
- ここの13日の数値を取り出そうとしています。
12
-
13
-
14
-
15
- ###発生している問題・エラーメッセージ
16
-
17
-
18
-
19
- NaNと出力される。
20
-
21
-
22
4
 
23
5
  ###該当のソースコード
24
-
25
- #!/usr/bin/ruby!
26
-
27
-
28
-
29
- ENV["SSL_CERT_FILE"] = "./cacert.pem"
30
-
31
-
32
-
33
- require 'mechanize'
34
-
35
-
36
-
37
- agent = Mechanize.new
38
-
39
- agent.user_agent_alias = 'Windows Mozilla'
40
-
41
- url = 'https://www.watashi-move.jp/wl/mydata/sphygmomanometer.php?targetDate=2016/07/01'
42
-
43
- page = agent.get(url)
44
-
45
- mypage = page.form_with(id: 'form1') do |form|
46
-
47
- form.loginid = '****'
48
-
49
- form.password = '***'
50
-
51
- end.submit
52
-
53
-
54
-
55
- require 'nokogiri'
56
-
57
- require 'open-uri'
58
-
59
- url = 'https://www.watashi-move.jp/wl/mydata/sphygmomanometer.php?targetDate=2016/07/01'
60
-
61
- user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36'
62
-
63
- charset = nil
64
-
65
- html = open(url, "User-Agent" => user_agent) do |f|
66
-
67
- charset = f.charset
68
-
69
- f.read
70
-
71
-
72
-
73
-
74
6
 
75
7
  doc = Nokogiri::HTML.parse(html, nil, charset)
76
8
 
77
9
  doc.xpath('//*div/div/div/div/div/div[@class="datas"]/tr[@id="lidtTr13"]/td[@class="pressureMin"]/span')
78
10
 
79
-
80
-
81
- puts doc.xpath('//*div/div/div/div/div/div[@class="datas"]/tr[@id="listTr13"]/td[@class="pressureMin"]/span')
11
+ puts doc.xpath('//*div/div/div/div/div/div[@class="datas"]/tr[@id="listTr13"]/td[@class="pressureMin"]/span')end
82
-
83
-
84
-
85
- end
86
-
87
-
88
12
 
89
13
  ###試したこと
90
14
 
91
- Xpathの部分を
15
+ Xpathの部分をdoc.xpath('//*[@class="datas"]/table[@class="datalist"]/tr[@id=listTr13]/td[@class="pressureMin"]/span')など試しましたがだめでした
92
16
 
93
- doc.xpath('//*[@class="datas"]/table[@class="datalist"]/tr[@id=listTr13]/td[@class="pressureMin"]/span')
17
+ ###HTML
94
18
 
95
-
19
+ 文字数の関係で13日以外削りました
96
20
 
97
- doc.xpath('//*div/div/div/div/div/div[@class="datas"]/tr[@id="lidtTr13"]/td[@class="pressureMin"]/span')
21
+ ```w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
98
22
 
99
- など試してみましたが、だめでした。
23
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
100
24
 
101
- よろしくお願い致します。
25
+ <head>
102
26
 
103
- ###補足情報(言語/FW/ツール等のバージョンなど)
27
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta http-equiv="Content-Style-Type" content="text/css" /><meta http-equiv="Content-Script-Type" content="text/javascript" /><meta name="robots" content="noindex,nofollow" />
104
28
 
105
- より詳細な情報
29
+ <title>閲覧</title>
30
+
31
+ <link rel="shortcut icon" href="/wl/images/common/favicon.ico" type="image/x-icon" /><link rel="stylesheet" type="text/css" href="/wl/css/common/reset_1610261.css" /><link rel="stylesheet" type="text/css" href="/wl/css/common/base_1610261.css" /><link rel="stylesheet" type="text/css" href="/wl/css/jcal_1610261.css" /><link rel="stylesheet" type="text/css" href="/wl/css/mydata_edit_common_1610261.css" /><link rel="stylesheet" type="text/css" href="/wl/css/mydata_sphygmomanometer_1610261.css" /><link rel="stylesheet" type="text/css" href="/wl/css/mydata_edit_ec_1610261.css" />
32
+
33
+ <script type="text/javascript" src="/wl/js/common/jquery-1.4.2.min.js" charset="utf-8"></script>
34
+
35
+ <script type="text/javascript" src="/wl/js/common/base_1610261.js" charset="utf-8"></script><script type="text/javascript" src="/wl/js/common/action_1610261.js" charset="utf-8"></script><script type="text/javascript" src="/wl/js/jcal_1610261.js" charset="utf-8"></script><script type="text/javascript" src="/wl/js/mydata_edit_cmn_1610261.js" charset="utf-8"></script><script type="text/javascript" src="/wl/js/config/pc_msg_ja_1610261.js" charset="utf-8"></script><script type="text/javascript" src="/wl/js/config/pc_mydata_label_ja_1610261.js" charset="utf-8"></script>
36
+
37
+ //<![CDATA[
38
+
39
+ var cookieOptions = {};
40
+
41
+ cookieOptions.expires = 9999;cookieOptions.path = "/";cookieOptions.domain = document.domain;
42
+
43
+ if ($.cookie("isBroadFont") == '1'){
44
+
45
+ $("head").append('<link rel="stylesheet" href="/member/css/common/meiryo_1610261.css" type="text/css" /> ');
46
+
47
+ } else if($.cookie("isBroadFont") == '2'){
48
+
49
+ $("head").append('<link rel="stylesheet" href="/member/css/common/hirakaku_1610261.css" type="text/css" /> ');}
50
+
51
+ jQuery(function(){
52
+
53
+ var d = new Detector();
54
+
55
+ if (d.test('メイリオ')){$("head").append('<link rel="stylesheet" href="/member/css/common/meiryo_1610261.css" type="text/css" /> ');
56
+
57
+ $.cookie("isBroadFont", '1', cookieOptions);} else if (d.test('HiraKakuPro-W3')){$("head").append('<link rel="stylesheet" href="/member/css/common/hirakaku_1610261.css" type="text/css" /> ');$.cookie("isBroadFont", '2', cookieOptions);}});
58
+
59
+ //]]>
60
+
61
+ </script>
62
+
63
+ <script type="text/javascript" charset="utf-8">
64
+
65
+ //<![CDATA[ var _gaq = _gaq || [];
66
+
67
+ _gaq.push(['_setAccount', 'UA-37292219-1']);
68
+
69
+ _gaq.push(['_setDomainName', 'www.watashi-move.jp']);
70
+
71
+ _gaq.push(['_trackPageview']);
72
+
73
+ (function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
74
+
75
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();
76
+
77
+ //]]>
78
+
79
+ </script></head>
80
+
81
+ <body>
82
+
83
+ <!-- header area start -->
84
+
85
+ <div id="headerArea"><div id="headerTop">
86
+
87
+ <h1><a name="home" href="https://www.watashi-move.jp/wl/home/index.php"><img src="/wl/images/common/logo_wellnesslink_0001.gif" alt="WellnessLINK" width="190" height="24" /></a></h1>
88
+
89
+ <ul><li class="noPipe"><a href="https://www.watashi-move.jp/member/profile/index.php" title="WM会員情報">WM会員情報</a></li><li ><a href="https://www.watashi-move.jp/member/support/index.php" title="サポート">サポート</a></li><li ><a href="http://www.watashi-move.jp/member/logout.php" title="ログアウト">ログアウト</a></li><li id="wmLogo" ><ahref="https://www.watashi-move.jp/member/home/index.php"><img src="/wl/images/common/logo_wm_0001.gif" alt="私ムーブ" width="58" height="24" /></a></li></ul></div>
90
+
91
+ <div id="globalNav">
92
+
93
+ <p id="statusUser"><a href="https://www.watashi-move.jp/member/profile/index.php" name="globalNavi">*さん</a></p>
94
+
95
+ <ul><li><a href="https://www.watashi-move.jp/wl/home/index.php" name="globalNavi"><img src="/wl/images/common/globalnav_home_0001.gif" alt="ホーム" width="110" height="40" class="rollover" /></a></li><li><a href="https://www.watashi-move.jp/wl/mygraph/index.php" name="globalNavi"><img src="/wl/images/common/globalnav_graph_0001.gif" alt="グラフ" width="130" height="40" class="rollover" /></a></li></ul></div></div>
96
+
97
+ <!-- header area end --><!-- container area start -->
98
+
99
+ <div id="contentArea">
100
+
101
+ <!-- main area start -->
102
+
103
+ <div id="content"><div id="contentWide">
104
+
105
+ <form id="vitalForm" name="sphygmomanometerform" method="post" action="">
106
+
107
+ <div class="navi clear">
108
+
109
+ <h2><img src="/wl/images/common/icon_measurementdata_0001.gif" alt="" width="41" height="41" class="icon" /><img src="/wl/images/h2_datalist_0001.gif" alt="メモ" width="114" height="18" /></h2>
110
+
111
+ <ul><li class="link"><div class="addLink"><p><img height="11" width="13" src="/wl/images/common/arrow2_0001.gif" alt=""> <a href="http://www.watashi-move.jp/pc/wm/help_m/index.html#58" class="subWindowOpen">ヘルプ</a></p></div></li></ul>
112
+
113
+ <ul><li><a class="backButton" href="sphygmomanometer.php?targetDate=2016/06/01"><img src="/wl/images/common/btn_date_back_0001.gif" alt="戻る" width="81" height="34" class="rollover" /></a></li><li id="date1" class="date">2016/07</li><li><a class="nextButton" href="sphygmomanometer.php?targetDate=2016/08/01"><img src="/wl/images/common/btn_date_next_0001.gif" alt="進む" width="81" height="34" class="rollover" /></a></li><li class="space">&nbsp;</li><li class="space cancel">&nbsp;</li><li class="space save"><a id="toEditMode" class="buttonLink" href="sphygmomanometer.php?editMode=editMode&amp;line=1&amp;targetDate=2016/07/01"><img src="/wl/images/common/btn_edit_0002.gif" alt="編集" width="142" height="34" class="rollover" /></a></li></ul></div>
114
+
115
+ <div class="notifyMessageArea clear"><div class="notifyMessage"><p>
116
+
117
+ &nbsp;</p></div>
118
+
119
+ <div class="adv"><p>&nbsp;</p></div></div>
120
+
121
+ <ul class="tab clear"><li class="stay"><strong>血圧計</strong></li>
122
+
123
+ <li><a class="tabLink" href="memo.php?targetDate=2016/07/01">メモ<a></li></ul>
124
+
125
+ <div class="box01Rounded clear"><div class="attention"><div class="hint"><span class="aten">※</span>入力必須</div>
126
+
127
+ <div class="links"><a href="http://www.watashi-move.jp/wl/mydata/csv.php?c=2&targetDate=2016/07/01" style="margin-left:5px">出力</a>
128
+
129
+ <a href="http://www.watashi-move.jp/wl/mydata/csv_all.php?c=2" onclick="return confirmSubmit();" style="margin-left:5px">出力</a>
130
+
131
+ <a href="http://www.watashi-move.jp/wl/mydata/MyData_HEM_201607.pdf?time=1478700665" target="_blank" style="margin-left:5px">印刷</a></div></div>
132
+
133
+ <div style="display:none;"><div style="display:none;" id="dummyArea"></div></div>
134
+
135
+ <div class="header"><table><tr class="headerLine1">
136
+
137
+ <th colspan="4" rowspan="2" class="date">2016年7月</th>
138
+
139
+ <th rowspan="2" class="time"><div class="glossary">時刻<span class="aten">※</span></th>
140
+
141
+ <th colspan="3" class="bloodPressure">血圧<span class="aten">※</span><em> (mmHg)</em></th><th rowspan="2" class="pulse">脈拍<br />
142
+
143
+ <em> (拍/分)</em></th><th colspan="2" class="takingMedicine">服薬</th><th rowspan="2" class="bpmemo">手帳<em></em></th><th rowspan="2" class="delete">削除</th><th rowspan="2" class="forScrollBar">&nbsp;</th></tr>
144
+
145
+ <tr class="headerLine2"><th class="pressureMax">最高血圧</th><th class="pressureSplit">/</th><th class="pressureMin">最低血圧</th><th class="takeMedicine">飲んだ</th><th class="notTakeMedicine">飲まな<br />かった</th></tr></table></div>
146
+
147
+ <div class="datas" >
148
+
149
+ <table id="sphygmomanometertable" class="datalist">
150
+
151
+ <tr id="listTr13" class="day13">
152
+
153
+ <td class="day">13</td>
154
+
155
+ <td class="week">水</td>
156
+
157
+ <td class="memo">&nbsp;</td>
158
+
159
+ <td class="btnAdd"></td>
160
+
161
+ <td class="time">13:44</td>
162
+
163
+ <td class="pressureMax"><span>93</span></td>
164
+
165
+ <td class="pressureSplit">/</td>
166
+
167
+ <td class="pressureMin"><span>59</span></td>
168
+
169
+ <td class="pulse_rate"><span>77</span></td>
170
+
171
+ <td class="takeMedicine"><input type="radio" name="take_medicine[13]" id="radio13-1" value="1" readonly="readonly" disabled="disabled" /></td>
172
+
173
+ <td class="notTakeMedicine"><input type="radio" name="take_medicine[13]" id="radio13-2" value="2" readonly="readonly" disabled="disabled" /></td>
174
+
175
+ <td class="bpmemo"></td>
176
+
177
+ <td class="btnDelete">&nbsp;<input type="hidden" id="day13" name="day[13]" value="13" /><input type="hidden" class="auto_flg" id="auto_flg13" name="auto_flg[13]" value="1" /><input type="hidden" id="day_group13" name="day_group[13]" value="13" /><input type="hidden" name="measure_start[13]" value="" /></td></tr>
178
+
179
+ </table></div>
180
+
181
+ </body>
182
+
183
+ </html>
184
+
185
+ ```