質問編集履歴

2

追記の質問

2018/04/27 22:01

投稿

Mario_11
Mario_11

スコア95

test CHANGED
File without changes
test CHANGED
@@ -28,107 +28,73 @@
28
28
 
29
29
  <p style="line-height: 13.33px; text-align: center">&#160;</p>
30
30
 
31
- </td>
31
+ </td>...
32
-
33
- <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">
34
-
35
- <p style="line-height: 13.33px; margin-right: 6px; text-align: right">
36
-
37
- <span style="font-family: 'MS Mincho'; font-size: 12px">34,303</span>
38
-
39
- </p>
40
-
41
- </td>
42
-
43
- <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">
44
-
45
- <p style="line-height: 13.33px; margin-right: 6px; text-align: right">
46
-
47
- <span style="font-family: 'MS Mincho'; font-size: 12px">36,762</span>
48
-
49
- </p>
50
-
51
- </td>
52
-
53
- <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">
54
-
55
- <p style="line-height: 13.33px; margin-right: 6px; text-align: right">
56
-
57
- <span style="font-family: 'MS Mincho'; font-size: 12px">28,016</span>
58
-
59
- </p>
60
-
61
- </td>
62
-
63
- </tr>
64
-
65
- <tr style="min-height: 27px">
66
-
67
- <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">
68
-
69
- <p style="margin-left: 30px; line-height: 13.33px; margin-right: 6px; text-align: left">
70
-
71
- <span style="font-family: 'MS Mincho'; font-size: 12px">流動負債合計</span>
72
-
73
- </p>
74
-
75
- </td>
76
-
77
- <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">
78
-
79
- <p style="line-height: 13.33px; text-align: center">&#160;</p>
80
-
81
- </td>
82
-
83
- <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">
84
-
85
- <p style="line-height: 13.33px; margin-right: 6px; text-align: right">
86
-
87
- <span style="font-family: 'MS Mincho'; font-size: 12px">6,917</span>
88
-
89
- </p>
90
-
91
- </td>
92
-
93
- <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">
94
-
95
- <p style="line-height: 13.33px; margin-right: 6px; text-align: right">
96
-
97
- <span style="font-family: 'MS Mincho'; font-size: 12px">6,809</span>
98
-
99
- </p>
100
-
101
- </td>
102
-
103
- <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">
104
-
105
- <p style="line-height: 13.33px; margin-right: 6px; text-align: right">
106
-
107
- <span style="font-family: 'MS Mincho'; font-size: 12px">5,339</span>
108
-
109
- </p>
110
-
111
- </td>
112
-
113
- </tr>
114
-
115
- 一部表示
116
32
 
117
33
  ```
118
34
 
119
- よろしくお願いいいたします。
120
-
121
-
122
-
123
- 追記です。
35
+ さらに追記です。
124
36
 
125
37
 
126
38
 
127
39
  ```java
128
40
 
41
+
42
+
43
+ /*
44
+
45
+ * To change this license header, choose License Headers in Project Properties.
46
+
47
+ * To change this template file, choose Tools | Templates
48
+
49
+ * and open the template in the editor.
50
+
51
+ */
52
+
53
+ package kakaku_com;
54
+
55
+
56
+
57
+ import java.io.PrintWriter;
58
+
59
+ import javax.servlet.ServletException;
60
+
61
+ import javax.servlet.http.HttpServlet;
62
+
63
+ import javax.servlet.http.HttpServletRequest;
64
+
65
+ import javax.servlet.http.HttpServletResponse;
66
+
67
+ import java.io.File;
68
+
69
+ import java.io.FileReader;
70
+
71
+ import java.io.IOException;
72
+
73
+ import javax.lang.model.util.Elements;
74
+
75
+ import org.jsoup.nodes.Element;
76
+
77
+ import org.w3c.dom.Document;
78
+
79
+
80
+
81
+
82
+
83
+ /**
84
+
85
+ *
86
+
87
+ * @author ichinosemasahiro
88
+
89
+ */
90
+
129
91
  public class serch_1 extends HttpServlet {
130
92
 
93
+
94
+
95
+ public class Main {
96
+
131
- public static void main(String[] args) {
97
+ public void takeurl(String[] args) {
132
98
 
133
99
  try {
134
100
 
@@ -168,44 +134,258 @@
168
134
 
169
135
  e.printStackTrace();
170
136
 
137
+
138
+
139
+ String html = "<tr style=\"min-height: 27px\">\r\n" +
140
+
141
+ "<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" +
142
+
143
+ "<p style=\"margin-left: 30px; line-height: 13.33px; margin-right: 6px; text-align: left\">\r\n" +
144
+
145
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">流動資産合計</span>\r\n" +
146
+
147
+ "</p>\r\n" +
148
+
149
+ "</td>\r\n" +
150
+
151
+ "<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" +
152
+
153
+ "<p style=\"line-height: 13.33px; text-align: center\">&#160;</p>\r\n" +
154
+
155
+ "</td>\r\n" +
156
+
157
+ "<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" +
158
+
159
+ "<p style=\"line-height: 13.33px; margin-right: 6px; text-align: right\">\r\n" +
160
+
161
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">34,303</span>\r\n" +
162
+
163
+ "</p>\r\n" +
164
+
165
+ "</td>\r\n" +
166
+
167
+ "<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" +
168
+
169
+ "<p style=\"line-height: 13.33px; margin-right: 6px; text-align: right\">\r\n" +
170
+
171
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">36,762</span>\r\n" +
172
+
173
+ "</p>\r\n" +
174
+
175
+ "</td>\r\n" +
176
+
177
+ "<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" +
178
+
179
+ "<p style=\"line-height: 13.33px; margin-right: 6px; text-align: right\">\r\n" +
180
+
181
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">28,016</span>\r\n" +
182
+
183
+ "</p>\r\n" +
184
+
185
+ "</td>\r\n" +
186
+
187
+ "</tr>\r\n" +
188
+
189
+ "<tr style=\"min-height: 27px\">\r\n" +
190
+
191
+ "<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" +
192
+
193
+ "<p style=\"margin-left: 30px; line-height: 13.33px; margin-right: 6px; text-align: left\">\r\n" +
194
+
195
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">流動負債合計</span>\r\n" +
196
+
197
+ "</p>\r\n" +
198
+
199
+ "</td>\r\n" +
200
+
201
+ "<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" +
202
+
203
+ "<p style=\"line-height: 13.33px; text-align: center\">&#160;</p>\r\n" +
204
+
205
+ "</td>\r\n" +
206
+
207
+ "<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" +
208
+
209
+ "<p style=\"line-height: 13.33px; margin-right: 6px; text-align: right\">\r\n" +
210
+
211
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">6,917</span>\r\n" +
212
+
213
+ "</p>\r\n" +
214
+
215
+ "</td>\r\n" +
216
+
217
+ "<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" +
218
+
219
+ "<p style=\"line-height: 13.33px; margin-right: 6px; text-align: right\">\r\n" +
220
+
221
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">6,809</span>\r\n" +
222
+
223
+ "</p>\r\n" +
224
+
225
+ "</td>\r\n" +
226
+
227
+ "<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" +
228
+
229
+ "<p style=\"line-height: 13.33px; margin-right: 6px; text-align: right\">\r\n" +
230
+
231
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">5,339</span>\r\n" +
232
+
233
+ "</p>\r\n" +
234
+
235
+ "</td>\r\n" +
236
+
237
+ "</tr>";
238
+
239
+ org.jsoup.nodes.Document doc = org.jsoup.Jsoup.parse(html);
240
+
241
+ org.jsoup.select.Elements spans = doc.select("span");
242
+
243
+ for (Element el : spans)
244
+
245
+ System.out.println(el.text());}
246
+
247
+ }
248
+
249
+
250
+
251
+ }
252
+
253
+
254
+
255
+ /**
256
+
257
+ * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
258
+
259
+ * methods.
260
+
261
+ *
262
+
263
+ * @param request servlet request
264
+
265
+ * @param response servlet response
266
+
267
+ * @throws ServletException if a servlet-specific error occurs
268
+
269
+ * @throws IOException if an I/O error occurs
270
+
271
+ */
272
+
273
+ protected void processRequest(HttpServletRequest request, HttpServletResponse response)
274
+
275
+ throws ServletException, IOException {
276
+
277
+ response.setContentType("text/html;charset=UTF-8");
278
+
279
+ try (PrintWriter out = response.getWriter()) {
280
+
281
+ /* TODO output your page here. You may use following sample code. */
282
+
283
+ out.println("<!DOCTYPE html>");
284
+
285
+ out.println("<html>");
286
+
287
+ out.println("<head>");
288
+
289
+ out.println("<title>Servlet serch_1</title>");
290
+
291
+ out.println("</head>");
292
+
293
+ out.println("<body>");
294
+
295
+ out.println("<h1>Servlet serch_1 at " + request.getContextPath() + "</h1>");
296
+
297
+ out.println("</body>");
298
+
299
+ out.println("</html>");
300
+
171
301
  }
172
302
 
173
-
174
-
175
- String html = "<tr style=\"min-height: 27px\">\r\n" +
176
-
177
- "<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" +
178
-
179
- "<p style=\"margin-left: 30px; line-height: 13.33px; margin-right: 6px; text-align: left\">\r\n" +
180
-
181
- "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">流動資産合計</span>\r\n" +
182
-
183
- "</p>\r\n" +
184
-
185
-
186
-
187
- Document doc = Jsoup.parse(html);
188
-
189
- Elements spans = doc.select("span");
190
-
191
- for (Element e : spans)
192
-
193
- System.out.println(e.text());
194
-
195
- }
303
+ }
304
+
305
+
306
+
307
+ // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
308
+
309
+ /**
310
+
311
+ * Handles the HTTP <code>GET</code> method.
312
+
313
+ *
314
+
315
+ * @param request servlet request
316
+
317
+ * @param response servlet response
318
+
319
+ * @throws ServletException if a servlet-specific error occurs
320
+
321
+ * @throws IOException if an I/O error occurs
322
+
323
+ */
324
+
325
+ @Override
326
+
327
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
328
+
329
+ throws ServletException, IOException {
330
+
331
+ processRequest(request, response);
332
+
333
+ }
334
+
335
+
336
+
337
+ /**
338
+
339
+ * Handles the HTTP <code>POST</code> method.
340
+
341
+ *
342
+
343
+ * @param request servlet request
344
+
345
+ * @param response servlet response
346
+
347
+ * @throws ServletException if a servlet-specific error occurs
348
+
349
+ * @throws IOException if an I/O error occurs
350
+
351
+ */
352
+
353
+ @Override
354
+
355
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
356
+
357
+ throws ServletException, IOException {
358
+
359
+ processRequest(request, response);
360
+
361
+ }
362
+
363
+
364
+
365
+ /**
366
+
367
+ * Returns a short description of the servlet.
368
+
369
+ *
370
+
371
+ * @return a String containing servlet description
372
+
373
+ */
374
+
375
+ @Override
376
+
377
+ public String getServletInfo() {
378
+
379
+ return "Short description";
380
+
381
+ }// </editor-fold>
382
+
383
+
384
+
385
+ }
386
+
387
+
196
388
 
197
389
  ```
198
390
 
199
- 書く場所がいまいちよくわかりません同じメソッド内に書いていいのでしょうか?
200
-
201
- これを見ながら自分でも
202
-
203
- 調べたのですが
204
-
205
- https://qiita.com/ota-meshi/items/5897d725dde372eac880
391
+ エラーは何も出ていないのですが、結果が思った通りに表示されませんでした、どこがおかしいのでしょうか。GWですが、よろしくお願いいたします!!
206
-
207
- documentのシンボルが見つけられないそうなのですがimportが必要なのですか?
208
-
209
- せっかく書いてもらったコードを理解できず申し訳ありません。
210
-
211
- よろしくお願いいたします

1

追記

2018/04/27 22:01

投稿

Mario_11
Mario_11

スコア95

test CHANGED
File without changes
test CHANGED
@@ -117,3 +117,95 @@
117
117
  ```
118
118
 
119
119
  よろしくお願いいいたします。
120
+
121
+
122
+
123
+ 追記です。
124
+
125
+
126
+
127
+ ```java
128
+
129
+ public class serch_1 extends HttpServlet {
130
+
131
+ public static void main(String[] args) {
132
+
133
+ try {
134
+
135
+ //Fileクラスに読み込むファイルを指定する
136
+
137
+ 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");
138
+
139
+ //ファイルが存在するか確認する
140
+
141
+ if(file.exists()) {
142
+
143
+ //FileReaderクラスのオブジェクトを生成する
144
+
145
+ FileReader filereader = new FileReader(file);
146
+
147
+ //filereaderクラスのreadメソッドでファイルを1文字ずつ読み込む
148
+
149
+ int data;
150
+
151
+ while((data = filereader.read()) != -1) {
152
+
153
+ System.out.print((char) data);
154
+
155
+ }
156
+
157
+ //ファイルクローズ
158
+
159
+ filereader.close();
160
+
161
+ } else {
162
+
163
+ System.out.print("ファイルは存在しません");
164
+
165
+ }
166
+
167
+ } catch (IOException e) {
168
+
169
+ e.printStackTrace();
170
+
171
+ }
172
+
173
+
174
+
175
+ String html = "<tr style=\"min-height: 27px\">\r\n" +
176
+
177
+ "<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" +
178
+
179
+ "<p style=\"margin-left: 30px; line-height: 13.33px; margin-right: 6px; text-align: left\">\r\n" +
180
+
181
+ "<span style=\"font-family: 'MS Mincho'; font-size: 12px\">流動資産合計</span>\r\n" +
182
+
183
+ "</p>\r\n" +
184
+
185
+
186
+
187
+ Document doc = Jsoup.parse(html);
188
+
189
+ Elements spans = doc.select("span");
190
+
191
+ for (Element e : spans)
192
+
193
+ System.out.println(e.text());
194
+
195
+ }
196
+
197
+ ```
198
+
199
+ 書く場所がいまいちよくわかりません同じメソッド内に書いていいのでしょうか?
200
+
201
+ これを見ながら自分でも
202
+
203
+ 調べたのですが
204
+
205
+ https://qiita.com/ota-meshi/items/5897d725dde372eac880
206
+
207
+ documentのシンボルが見つけられないそうなのですがimportが必要なのですか?
208
+
209
+ せっかく書いてもらったコードを理解できず申し訳ありません。
210
+
211
+ よろしくお願いいたします