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

質問編集履歴

2

追記の質問

2018/04/27 22:01

投稿

Mario_11
Mario_11

スコア95

title CHANGED
File without changes
body CHANGED
@@ -13,57 +13,40 @@
13
13
  </td>
14
14
  <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
15
15
  <p style="line-height: 13.33px; text-align: center">&#160;</p>
16
- </td>
16
+ </td>...
17
- <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
18
- <p style="line-height: 13.33px; margin-right: 6px; text-align: right">
19
- <span style="font-family: 'MS Mincho'; font-size: 12px">34,303</span>
20
- </p>
21
- </td>
22
- <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
23
- <p style="line-height: 13.33px; margin-right: 6px; text-align: right">
24
- <span style="font-family: 'MS Mincho'; font-size: 12px">36,762</span>
25
- </p>
26
- </td>
27
- <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
28
- <p style="line-height: 13.33px; margin-right: 6px; text-align: right">
29
- <span style="font-family: 'MS Mincho'; font-size: 12px">28,016</span>
30
- </p>
31
- </td>
32
- </tr>
33
- <tr style="min-height: 27px">
34
- <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
35
- <p style="margin-left: 30px; line-height: 13.33px; margin-right: 6px; text-align: left">
36
- <span style="font-family: 'MS Mincho'; font-size: 12px">流動負債合計</span>
37
- </p>
38
- </td>
39
- <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
40
- <p style="line-height: 13.33px; text-align: center">&#160;</p>
41
- </td>
42
- <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
43
- <p style="line-height: 13.33px; margin-right: 6px; text-align: right">
44
- <span style="font-family: 'MS Mincho'; font-size: 12px">6,917</span>
45
- </p>
46
- </td>
47
- <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
48
- <p style="line-height: 13.33px; margin-right: 6px; text-align: right">
49
- <span style="font-family: 'MS Mincho'; font-size: 12px">6,809</span>
50
- </p>
51
- </td>
52
- <td style="border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle">
53
- <p style="line-height: 13.33px; margin-right: 6px; text-align: right">
54
- <span style="font-family: 'MS Mincho'; font-size: 12px">5,339</span>
55
- </p>
56
- </td>
57
- </tr>
58
- 一部表示
59
17
  ```
60
- よろしくお願いいいたします。
18
+ さらに追記です。
61
19
 
62
- 追記です。
20
+ ```java
63
21
 
64
- ```java
22
+ /*
23
+ * To change this license header, choose License Headers in Project Properties.
24
+ * To change this template file, choose Tools | Templates
25
+ * and open the template in the editor.
26
+ */
27
+ package kakaku_com;
28
+
29
+ import java.io.PrintWriter;
30
+ import javax.servlet.ServletException;
31
+ import javax.servlet.http.HttpServlet;
32
+ import javax.servlet.http.HttpServletRequest;
33
+ import javax.servlet.http.HttpServletResponse;
34
+ import java.io.File;
35
+ import java.io.FileReader;
36
+ import java.io.IOException;
37
+ import javax.lang.model.util.Elements;
38
+ import org.jsoup.nodes.Element;
39
+ import org.w3c.dom.Document;
40
+
41
+
42
+ /**
43
+ *
44
+ * @author ichinosemasahiro
45
+ */
65
46
  public class serch_1 extends HttpServlet {
47
+
48
+ public class Main {
66
- public static void main(String[] args) {
49
+ public void takeurl(String[] args) {
67
50
  try {
68
51
  //Fileクラスに読み込むファイルを指定する
69
52
  File file = new File("/Users/ichinosemasahiro/Desktop/Xbrl_Search_20180426_120405/S100CBQ2/XBRL/PublicDoc/0104020_honbun_jpcrp040300-q3r-001_E05350-000_2017-12-31_01_2018-02-09_ixbrl.htm");
@@ -83,24 +66,131 @@
83
66
  }
84
67
  } catch (IOException e) {
85
68
  e.printStackTrace();
69
+
70
+ String html = "<tr style=\"min-height: 27px\">\r\n" +
71
+ "<td style=\"border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle\">\r\n" +
72
+ "<p style=\"margin-left: 30px; line-height: 13.33px; margin-right: 6px; text-align: left\">\r\n" +
73
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">流動資産合計</span>\r\n" +
74
+ "</p>\r\n" +
75
+ "</td>\r\n" +
76
+ "<td style=\"border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle\">\r\n" +
77
+ "<p style=\"line-height: 13.33px; text-align: center\">&#160;</p>\r\n" +
78
+ "</td>\r\n" +
79
+ "<td style=\"border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle\">\r\n" +
80
+ "<p style=\"line-height: 13.33px; margin-right: 6px; text-align: right\">\r\n" +
81
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">34,303</span>\r\n" +
82
+ "</p>\r\n" +
83
+ "</td>\r\n" +
84
+ "<td style=\"border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle\">\r\n" +
85
+ "<p style=\"line-height: 13.33px; margin-right: 6px; text-align: right\">\r\n" +
86
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">36,762</span>\r\n" +
87
+ "</p>\r\n" +
88
+ "</td>\r\n" +
89
+ "<td style=\"border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle\">\r\n" +
90
+ "<p style=\"line-height: 13.33px; margin-right: 6px; text-align: right\">\r\n" +
91
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">28,016</span>\r\n" +
92
+ "</p>\r\n" +
93
+ "</td>\r\n" +
94
+ "</tr>\r\n" +
95
+ "<tr style=\"min-height: 27px\">\r\n" +
96
+ "<td style=\"border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle\">\r\n" +
97
+ "<p style=\"margin-left: 30px; line-height: 13.33px; margin-right: 6px; text-align: left\">\r\n" +
98
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">流動負債合計</span>\r\n" +
99
+ "</p>\r\n" +
100
+ "</td>\r\n" +
101
+ "<td style=\"border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle\">\r\n" +
102
+ "<p style=\"line-height: 13.33px; text-align: center\">&#160;</p>\r\n" +
103
+ "</td>\r\n" +
104
+ "<td style=\"border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle\">\r\n" +
105
+ "<p style=\"line-height: 13.33px; margin-right: 6px; text-align: right\">\r\n" +
106
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">6,917</span>\r\n" +
107
+ "</p>\r\n" +
108
+ "</td>\r\n" +
109
+ "<td style=\"border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle\">\r\n" +
110
+ "<p style=\"line-height: 13.33px; margin-right: 6px; text-align: right\">\r\n" +
111
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">6,809</span>\r\n" +
112
+ "</p>\r\n" +
113
+ "</td>\r\n" +
114
+ "<td style=\"border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle\">\r\n" +
115
+ "<p style=\"line-height: 13.33px; margin-right: 6px; text-align: right\">\r\n" +
116
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">5,339</span>\r\n" +
117
+ "</p>\r\n" +
118
+ "</td>\r\n" +
119
+ "</tr>";
120
+ org.jsoup.nodes.Document doc = org.jsoup.Jsoup.parse(html);
121
+ org.jsoup.select.Elements spans = doc.select("span");
122
+ for (Element el : spans)
123
+ System.out.println(el.text());}
124
+ }
125
+
126
+ }
127
+
128
+ /**
129
+ * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
130
+ * methods.
131
+ *
132
+ * @param request servlet request
133
+ * @param response servlet response
134
+ * @throws ServletException if a servlet-specific error occurs
135
+ * @throws IOException if an I/O error occurs
136
+ */
137
+ protected void processRequest(HttpServletRequest request, HttpServletResponse response)
138
+ throws ServletException, IOException {
139
+ response.setContentType("text/html;charset=UTF-8");
140
+ try (PrintWriter out = response.getWriter()) {
141
+ /* TODO output your page here. You may use following sample code. */
142
+ out.println("<!DOCTYPE html>");
143
+ out.println("<html>");
144
+ out.println("<head>");
145
+ out.println("<title>Servlet serch_1</title>");
146
+ out.println("</head>");
147
+ out.println("<body>");
148
+ out.println("<h1>Servlet serch_1 at " + request.getContextPath() + "</h1>");
149
+ out.println("</body>");
150
+ out.println("</html>");
86
151
  }
87
-
88
- String html = "<tr style=\"min-height: 27px\">\r\n" +
89
- "<td style=\"border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle\">\r\n" +
90
- "<p style=\"margin-left: 30px; line-height: 13.33px; margin-right: 6px; text-align: left\">\r\n" +
91
- "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">流動資産合計</span>\r\n" +
92
- "</p>\r\n" +
93
-
94
- Document doc = Jsoup.parse(html);
95
- Elements spans = doc.select("span");
96
- for (Element e : spans)
97
- System.out.println(e.text());
98
- }
152
+ }
153
+
154
+ // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
155
+ /**
156
+ * Handles the HTTP <code>GET</code> method.
157
+ *
158
+ * @param request servlet request
159
+ * @param response servlet response
160
+ * @throws ServletException if a servlet-specific error occurs
161
+ * @throws IOException if an I/O error occurs
162
+ */
163
+ @Override
164
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
165
+ throws ServletException, IOException {
166
+ processRequest(request, response);
167
+ }
168
+
169
+ /**
170
+ * Handles the HTTP <code>POST</code> method.
171
+ *
172
+ * @param request servlet request
173
+ * @param response servlet response
174
+ * @throws ServletException if a servlet-specific error occurs
175
+ * @throws IOException if an I/O error occurs
176
+ */
177
+ @Override
178
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
179
+ throws ServletException, IOException {
180
+ processRequest(request, response);
181
+ }
182
+
183
+ /**
184
+ * Returns a short description of the servlet.
185
+ *
186
+ * @return a String containing servlet description
187
+ */
188
+ @Override
189
+ public String getServletInfo() {
190
+ return "Short description";
191
+ }// </editor-fold>
192
+
193
+ }
194
+
99
195
  ```
100
- 書く場所がいまいちよくわかりません同じメソッド内に書いていいのでしょうか?
101
- これを見ながら自分でも
102
- 調べたのですが
103
- https://qiita.com/ota-meshi/items/5897d725dde372eac880
196
+ エラーは何も出ていないのですが、結果が思った通りに表示されませんでした、どこがおかしいのでしょうか。GWですが、よろしくお願いいたします!!
104
- documentのシンボルが見つけられないそうなのですがimportが必要なのですか?
105
- せっかく書いてもらったコードを理解できず申し訳ありません。
106
- よろしくお願いいたします

1

追記

2018/04/27 22:01

投稿

Mario_11
Mario_11

スコア95

title CHANGED
File without changes
body CHANGED
@@ -57,4 +57,50 @@
57
57
  </tr>
58
58
  一部表示
59
59
  ```
60
- よろしくお願いいいたします。
60
+ よろしくお願いいいたします。
61
+
62
+ 追記です。
63
+
64
+ ```java
65
+ public class serch_1 extends HttpServlet {
66
+ public static void main(String[] args) {
67
+ try {
68
+ //Fileクラスに読み込むファイルを指定する
69
+ File file = new File("/Users/ichinosemasahiro/Desktop/Xbrl_Search_20180426_120405/S100CBQ2/XBRL/PublicDoc/0104020_honbun_jpcrp040300-q3r-001_E05350-000_2017-12-31_01_2018-02-09_ixbrl.htm");
70
+ //ファイルが存在するか確認する
71
+ if(file.exists()) {
72
+ //FileReaderクラスのオブジェクトを生成する
73
+ FileReader filereader = new FileReader(file);
74
+ //filereaderクラスのreadメソッドでファイルを1文字ずつ読み込む
75
+ int data;
76
+ while((data = filereader.read()) != -1) {
77
+ System.out.print((char) data);
78
+ }
79
+ //ファイルクローズ
80
+ filereader.close();
81
+ } else {
82
+ System.out.print("ファイルは存在しません");
83
+ }
84
+ } catch (IOException e) {
85
+ e.printStackTrace();
86
+ }
87
+
88
+ String html = "<tr style=\"min-height: 27px\">\r\n" +
89
+ "<td style=\"border-left: 1px solid #000000; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; vertical-align: middle\">\r\n" +
90
+ "<p style=\"margin-left: 30px; line-height: 13.33px; margin-right: 6px; text-align: left\">\r\n" +
91
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">流動資産合計</span>\r\n" +
92
+ "</p>\r\n" +
93
+
94
+ Document doc = Jsoup.parse(html);
95
+ Elements spans = doc.select("span");
96
+ for (Element e : spans)
97
+ System.out.println(e.text());
98
+ }
99
+ ```
100
+ 書く場所がいまいちよくわかりません同じメソッド内に書いていいのでしょうか?
101
+ これを見ながら自分でも
102
+ 調べたのですが
103
+ https://qiita.com/ota-meshi/items/5897d725dde372eac880
104
+ documentのシンボルが見つけられないそうなのですがimportが必要なのですか?
105
+ せっかく書いてもらったコードを理解できず申し訳ありません。
106
+ よろしくお願いいたします