質問するログイン新規登録

質問編集履歴

3

誤字

2016/11/11 05:43

投稿

shigahi
shigahi

スコア21

title CHANGED
File without changes
body CHANGED
@@ -22,8 +22,8 @@
22
22
  charset = f.charset
23
23
  f.read
24
24
  doc = Nokogiri::HTML.parse(html, nil, charset)
25
- doc.xpath('//tr[@class="day13"]/td[@class="pressureMin"]')
25
+ doc.xpath('//tr[@class="day13"]/td[@class="pressureMin"]').text
26
- puts doc.xpath('//tr[@class="day13"]/td[@class="pressureMin"]')
26
+ puts doc.xpath('//tr[@class="day13"]/td[@class="pressureMin"]').text
27
27
  end
28
28
  ```
29
29
  ###試したこと

2

プログラムの追加

2016/11/11 05:43

投稿

shigahi
shigahi

スコア21

title CHANGED
File without changes
body CHANGED
@@ -1,9 +1,31 @@
1
1
  #実現したいこと
2
2
  nokogiriを使って数値を抽出しようとしているのですが実行するとNaNとだけ出力されてしまいます。Webページは血圧計の結果を送ると表に記録されます。13日の値を取り出そうとしています
3
3
  ###該当のソースコード
4
+ ```ruby
5
+ #!/usr/bin/ruby
6
+ require 'mechanize'
7
+ agent = Mechanize.new
8
+ agent.user_agent_alias = 'Windows Mozilla'
9
+ url = 'https://www.watashi-move.jp/wl/mydata/sphygmomanometer.php?targetDate=2016/07/01'
10
+ page = agent.get(url)
11
+ mypage = page.form_with(id: 'form1') do |form|
12
+ form.loginid = '*'
13
+ form.password = '*'
14
+ end.submit
15
+
16
+ require 'nokogiri'
17
+ require 'open-uri'
18
+ url = 'https://www.watashi-move.jp/wl/mydata/sphygmomanometer.php?targetDate=2016/07/01'
19
+ user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36'
20
+ charset = nil
21
+ html = open(url, "User-Agent" => user_agent) do |f|
22
+ charset = f.charset
23
+ f.read
4
24
  doc = Nokogiri::HTML.parse(html, nil, charset)
5
- doc.xpath('//*div/div/div/div/div/div[@class="datas"]/tr[@id="lidtTr13"]/td[@class="pressureMin"]/span')
25
+ doc.xpath('//tr[@class="day13"]/td[@class="pressureMin"]')
6
- puts doc.xpath('//*div/div/div/div/div/div[@class="datas"]/tr[@id="listTr13"]/td[@class="pressureMin"]/span')end
26
+ puts doc.xpath('//tr[@class="day13"]/td[@class="pressureMin"]')
27
+ end
28
+ ```
7
29
  ###試したこと
8
30
  Xpathの部分をdoc.xpath('//*[@class="datas"]/table[@class="datalist"]/tr[@id=listTr13]/td[@class="pressureMin"]/span')など試しましたがだめでした
9
31
  ###HTML

1

htmlの追加

2016/11/11 05:42

投稿

shigahi
shigahi

スコア21

title CHANGED
File without changes
body CHANGED
@@ -1,53 +1,93 @@
1
1
  #実現したいこと
2
- webページの数値が記載された表から、nokogiriを使って数値を抽出しようとしているのですが実行するとNaNとだけ出力されてしまいます。
2
+ nokogiriを使って数値を抽出しようとしているのですが実行するとNaNとだけ出力されてしまいます。Webページは血圧計の結果を送ると表に記録されます。13日の値を取り出そうとしています
3
- Webページはオムロンのウェルネスリンクというところの、血圧測定器の結果を送ると、
4
- ![イメージ説明](5bd8e508ea454f0c61965e5be29d69ae.png)
5
- このような表に記録されます。
6
- ここの13日の数値を取り出そうとしています。
7
-
8
- ###発生している問題・エラーメッセージ
9
-
10
- NaNと出力される。
11
-
12
3
  ###該当のソースコード
13
- #!/usr/bin/ruby!
14
-
15
- ENV["SSL_CERT_FILE"] = "./cacert.pem"
16
-
17
- require 'mechanize'
18
-
19
- agent = Mechanize.new
20
- agent.user_agent_alias = 'Windows Mozilla'
21
- url = 'https://www.watashi-move.jp/wl/mydata/sphygmomanometer.php?targetDate=2016/07/01'
22
- page = agent.get(url)
23
- mypage = page.form_with(id: 'form1') do |form|
24
- form.loginid = '****'
25
- form.password = '***'
26
- end.submit
27
-
28
- require 'nokogiri'
29
- require 'open-uri'
30
- url = 'https://www.watashi-move.jp/wl/mydata/sphygmomanometer.php?targetDate=2016/07/01'
31
- user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36'
32
- charset = nil
33
- html = open(url, "User-Agent" => user_agent) do |f|
34
- charset = f.charset
35
- f.read
36
-
37
-
38
4
  doc = Nokogiri::HTML.parse(html, nil, charset)
39
5
  doc.xpath('//*div/div/div/div/div/div[@class="datas"]/tr[@id="lidtTr13"]/td[@class="pressureMin"]/span')
40
-
41
- puts doc.xpath('//*div/div/div/div/div/div[@class="datas"]/tr[@id="listTr13"]/td[@class="pressureMin"]/span')
6
+ puts doc.xpath('//*div/div/div/div/div/div[@class="datas"]/tr[@id="listTr13"]/td[@class="pressureMin"]/span')end
42
-
43
- end
44
-
45
7
  ###試したこと
46
- Xpathの部分を
47
- doc.xpath('//*[@class="datas"]/table[@class="datalist"]/tr[@id=listTr13]/td[@class="pressureMin"]/span')
48
-
49
- doc.xpath('//*div/div/div/div/div/div[@class="datas"]/tr[@id="lidtTr13"]/td[@class="pressureMin"]/span')
50
- など試してみましたが、だめでした。
51
- よろしくお願い致します。
52
- ###補足情報(言語/FW/ツール等のバージョンなど)
53
- より詳細な情報
8
+ Xpathの部分をdoc.xpath('//*[@class="datas"]/table[@class="datalist"]/tr[@id=listTr13]/td[@class="pressureMin"]/span')など試しましたがだめでした
9
+ ###HTML
10
+ 文字数の関係で13日以外削りました
11
+ ```w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
12
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
13
+ <head>
14
+ <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" />
15
+ <title>閲覧</title>
16
+ <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" />
17
+ <script type="text/javascript" src="/wl/js/common/jquery-1.4.2.min.js" charset="utf-8"></script>
18
+ <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>
19
+ //<![CDATA[
20
+ var cookieOptions = {};
21
+ cookieOptions.expires = 9999;cookieOptions.path = "/";cookieOptions.domain = document.domain;
22
+ if ($.cookie("isBroadFont") == '1'){
23
+ $("head").append('<link rel="stylesheet" href="/member/css/common/meiryo_1610261.css" type="text/css" /> ');
24
+ } else if($.cookie("isBroadFont") == '2'){
25
+ $("head").append('<link rel="stylesheet" href="/member/css/common/hirakaku_1610261.css" type="text/css" /> ');}
26
+ jQuery(function(){
27
+ var d = new Detector();
28
+ if (d.test('メイリオ')){$("head").append('<link rel="stylesheet" href="/member/css/common/meiryo_1610261.css" type="text/css" /> ');
29
+ $.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);}});
30
+ //]]>
31
+ </script>
32
+ <script type="text/javascript" charset="utf-8">
33
+ //<![CDATA[ var _gaq = _gaq || [];
34
+ _gaq.push(['_setAccount', 'UA-37292219-1']);
35
+ _gaq.push(['_setDomainName', 'www.watashi-move.jp']);
36
+ _gaq.push(['_trackPageview']);
37
+ (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';
38
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();
39
+ //]]>
40
+ </script></head>
41
+ <body>
42
+ <!-- header area start -->
43
+ <div id="headerArea"><div id="headerTop">
44
+ <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>
45
+ <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>
46
+ <div id="globalNav">
47
+ <p id="statusUser"><a href="https://www.watashi-move.jp/member/profile/index.php" name="globalNavi">*さん</a></p>
48
+ <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>
49
+ <!-- header area end --><!-- container area start -->
50
+ <div id="contentArea">
51
+ <!-- main area start -->
52
+ <div id="content"><div id="contentWide">
53
+ <form id="vitalForm" name="sphygmomanometerform" method="post" action="">
54
+ <div class="navi clear">
55
+ <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>
56
+ <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>
57
+ <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>
58
+ <div class="notifyMessageArea clear"><div class="notifyMessage"><p>
59
+ &nbsp;</p></div>
60
+ <div class="adv"><p>&nbsp;</p></div></div>
61
+ <ul class="tab clear"><li class="stay"><strong>血圧計</strong></li>
62
+ <li><a class="tabLink" href="memo.php?targetDate=2016/07/01">メモ<a></li></ul>
63
+ <div class="box01Rounded clear"><div class="attention"><div class="hint"><span class="aten">※</span>入力必須</div>
64
+ <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>
65
+ <a href="http://www.watashi-move.jp/wl/mydata/csv_all.php?c=2" onclick="return confirmSubmit();" style="margin-left:5px">出力</a>
66
+ <a href="http://www.watashi-move.jp/wl/mydata/MyData_HEM_201607.pdf?time=1478700665" target="_blank" style="margin-left:5px">印刷</a></div></div>
67
+ <div style="display:none;"><div style="display:none;" id="dummyArea"></div></div>
68
+ <div class="header"><table><tr class="headerLine1">
69
+ <th colspan="4" rowspan="2" class="date">2016年7月</th>
70
+ <th rowspan="2" class="time"><div class="glossary">時刻<span class="aten">※</span></th>
71
+ <th colspan="3" class="bloodPressure">血圧<span class="aten">※</span><em> (mmHg)</em></th><th rowspan="2" class="pulse">脈拍<br />
72
+ <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>
73
+ <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>
74
+ <div class="datas" >
75
+ <table id="sphygmomanometertable" class="datalist">
76
+ <tr id="listTr13" class="day13">
77
+ <td class="day">13</td>
78
+ <td class="week">水</td>
79
+ <td class="memo">&nbsp;</td>
80
+ <td class="btnAdd"></td>
81
+ <td class="time">13:44</td>
82
+ <td class="pressureMax"><span>93</span></td>
83
+ <td class="pressureSplit">/</td>
84
+ <td class="pressureMin"><span>59</span></td>
85
+ <td class="pulse_rate"><span>77</span></td>
86
+ <td class="takeMedicine"><input type="radio" name="take_medicine[13]" id="radio13-1" value="1" readonly="readonly" disabled="disabled" /></td>
87
+ <td class="notTakeMedicine"><input type="radio" name="take_medicine[13]" id="radio13-2" value="2" readonly="readonly" disabled="disabled" /></td>
88
+ <td class="bpmemo"></td>
89
+ <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>
90
+ </table></div>
91
+ </body>
92
+ </html>
93
+ ```