• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

作業部屋の使い方を試しています。


Commit MetaInfo

Revision135 (tree)
Time2016-05-05 14:38:55
Authortuna_p

Log Message

結果返却方法改良

Change Summary

Incremental Difference

--- branches/b4/webScraping/src/WebScraping/utility/HtmlSearch.java (revision 134)
+++ branches/b4/webScraping/src/WebScraping/utility/HtmlSearch.java (revision 135)
@@ -21,13 +21,16 @@
2121 */
2222 package webScraping.utility;
2323
24+import WebScraping.core.Scraping;
2425 import webScraping.core.HtmlParser;
2526 import webScraping.core.SearchData;
2627 import java.awt.Desktop;
2728 import java.io.File;
2829 import java.io.IOException;
30+import java.net.MalformedURLException;
2931 import java.net.URI;
3032 import java.net.URISyntaxException;
33+import java.net.URL;
3134 import java.util.logging.Level;
3235 import java.util.logging.Logger;
3336 import javax.swing.JFileChooser;
@@ -391,7 +394,7 @@
391394 /**
392395 * 検索実行.
393396 */
394- void Search_execution() {
397+ void Search_execution_old() {
395398 jTxtRtn.setText(null);
396399 HtmlParser par = new HtmlParser(jTxtUrl.getText());
397400
@@ -422,6 +425,43 @@
422425 }
423426
424427 /**
428+ * 検索実行.
429+ */
430+ void Search_execution() {
431+ jTxtRtn.setText(null);
432+ Scraping scrap = new Scraping();
433+
434+ URL url = null;
435+ try {
436+ url = new URL(jTxtUrl.getText());
437+ } catch (MalformedURLException ex) {
438+ Logger.getLogger(HtmlSearch.class.getName()).log(Level.SEVERE, null, ex);
439+ }
440+
441+ SearchData[] skey = new SearchData[sdatatblmodel.getRowCount()];
442+ for(int row = 0; row < sdatatblmodel.getRowCount(); row++) {
443+ skey[row] = sdatatblmodel.getSearchData(row);
444+ }
445+
446+ // HTML検索
447+ String[] result = scrap.getResult(url, skey);
448+
449+ // 検索結果
450+ if(result == null) {
451+ jTxtRtn.append("Data not find");
452+ return;
453+ }
454+
455+ for(int i = 0; i < skey.length; i++) {
456+ String ans = skey[i].getitem();
457+ String rtn = result[i];
458+ jTxtRtn.append(ans + "\t" + rtn + "\n");
459+ }
460+
461+ jTxtRtn.setCaretPosition(0);
462+ }
463+
464+ /**
425465 * @param args the command line arguments
426466 */
427467 public static void main(String args[]) {
--- branches/b4/webScraping/src/WebScraping/core/Scraping.java (nonexistent)
+++ branches/b4/webScraping/src/WebScraping/core/Scraping.java (revision 135)
@@ -0,0 +1,74 @@
1+/*
2+ * Copyright (C) 2016 kgto.
3+ *
4+ * This library is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * This library is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with this library; if not, write to the Free Software
16+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+ * MA 02110-1301 USA
18+ */
19+/*
20+ * $Id: $
21+ */
22+package WebScraping.core;
23+
24+import java.net.URL;
25+import webScraping.core.HtmlParser;
26+import webScraping.core.SearchData;
27+
28+/**
29+ *
30+ * @author kgto
31+ */
32+public class Scraping {
33+
34+ /**
35+ * HTML解析.
36+ * @param url
37+ * @param skey
38+ * @return
39+ */
40+ public String[] getResult(URL url, SearchData[] skey) {
41+
42+ HtmlParser par = new HtmlParser(url);
43+
44+ String[] result = new String[skey.length];
45+ for(int i = 0; i < skey.length; i++) {
46+ result[i] = par.search(skey[i]);
47+ }
48+
49+ if(!resultCheck(result)) {
50+ return null;
51+ }
52+ return result;
53+ }
54+
55+ /**
56+ * 結果文字列チェック.
57+ * @param result
58+ * @return 文字列配列に1文字でも入力有り(null/SPACE以外)の時、true
59+ */
60+ boolean resultCheck(String[] result) {
61+ for(int i = 0; i < result.length; i++) {
62+ String str = "";
63+ if(result[i] != null) {
64+ str = result[i].trim();
65+ }
66+
67+ if(str.length() > 0) {
68+ return true;
69+ }
70+ }
71+ return false;
72+ }
73+
74+}