作業部屋の使い方を試しています。
HTML属性の取得方法を考える。
| @@ -0,0 +1,124 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2014 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 | +package Lib; | |
| 21 | + | |
| 22 | +import java.util.ArrayList; | |
| 23 | +import java.util.Enumeration; | |
| 24 | +import javax.swing.text.MutableAttributeSet; | |
| 25 | +import javax.swing.text.html.HTML; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * | |
| 29 | + * @author kgto | |
| 30 | + */ | |
| 31 | +public class AttributeData { | |
| 32 | + | |
| 33 | + public AttributeData() { | |
| 34 | + AttrList = new ArrayList(); | |
| 35 | + } | |
| 36 | + | |
| 37 | + public void add(HTML.Tag tag, MutableAttributeSet attr) { | |
| 38 | + | |
| 39 | + int tagcount = tagcnt(tag); | |
| 40 | + ++tagcount; | |
| 41 | + | |
| 42 | + Enumeration e = attr.getAttributeNames(); | |
| 43 | + while(e.hasMoreElements()) { | |
| 44 | + Object obj = e.nextElement(); | |
| 45 | + | |
| 46 | + AttrData a = new AttrData(); | |
| 47 | + a.tag = tag; | |
| 48 | + a.count = tagcount; | |
| 49 | + a.attrname = obj.toString(); | |
| 50 | + a.attrvalue = (String)attr.getAttribute(obj); | |
| 51 | + | |
| 52 | + AttrList.add(a); | |
| 53 | + } | |
| 54 | + | |
| 55 | + } | |
| 56 | + | |
| 57 | + public boolean search(HTML.Tag tag, String attrname, String attrvalue) { | |
| 58 | + boolean ret = false; | |
| 59 | + for (Object AttrList1 : AttrList) { | |
| 60 | + AttrData a = (AttrData)AttrList1; | |
| 61 | + if(a.tag == tag) { | |
| 62 | + if(a.attrname.equals(attrname) && a.attrvalue.equals(attrvalue)) { | |
| 63 | + ret = true; | |
| 64 | + } | |
| 65 | + } | |
| 66 | + } | |
| 67 | + return ret; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public boolean searchId(HTML.Tag tag, String attrvalue) { | |
| 71 | + return search(tag, "id", attrvalue); | |
| 72 | + } | |
| 73 | + | |
| 74 | + public boolean searchClass(HTML.Tag tag, String attrvalue) { | |
| 75 | + return search(tag, "class", attrvalue); | |
| 76 | + } | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * 属性の値を取得する. | |
| 80 | + * @param tag | |
| 81 | + * @param attrname | |
| 82 | + * @return | |
| 83 | + */ | |
| 84 | + public ArrayList getvale(HTML.Tag tag, String attrname) { | |
| 85 | + ArrayList ret = new ArrayList(); | |
| 86 | + for (Object AttrList1 : AttrList) { | |
| 87 | + AttrData a = (AttrData)AttrList1; | |
| 88 | + if(a.tag == tag) { | |
| 89 | + if(a.attrname.equals(attrname)) { | |
| 90 | + ret.add(a.attrvalue); | |
| 91 | + } | |
| 92 | + } | |
| 93 | + } | |
| 94 | + return ret; | |
| 95 | + } | |
| 96 | + | |
| 97 | + /** | |
| 98 | + * 引数で渡されたTAGの最新カウント数を返す. | |
| 99 | + * @param tag | |
| 100 | + * @return | |
| 101 | + */ | |
| 102 | + private int tagcnt(HTML.Tag tag) { | |
| 103 | + int wkcnt = 0; | |
| 104 | + for (Object AttrList1 : AttrList) { | |
| 105 | + AttrData a = (AttrData)AttrList1; | |
| 106 | + if(a.tag == tag) { | |
| 107 | + if(wkcnt < a.count) { | |
| 108 | + wkcnt = a.count; | |
| 109 | + } | |
| 110 | + } | |
| 111 | + } | |
| 112 | + return wkcnt; | |
| 113 | + } | |
| 114 | + | |
| 115 | + // フィールド変数 | |
| 116 | + public class AttrData { | |
| 117 | + public HTML.Tag tag; | |
| 118 | + public int count; | |
| 119 | + public String attrname; | |
| 120 | + public String attrvalue; | |
| 121 | + } | |
| 122 | + public ArrayList AttrList; | |
| 123 | + | |
| 124 | +} |
| @@ -0,0 +1,14 @@ | ||
| 1 | +http://weather.yahoo.co.jp/weather/ | |
| 2 | +天気01 li point pt1400 | |
| 3 | +天気02 li point pt1900 | |
| 4 | +天気03 li point pt3410 | |
| 5 | +天気04 li point pt4410 | |
| 6 | +天気05 li point pt5110 | |
| 7 | +天気06 li point pt5410 | |
| 8 | +天気07 li point pt5610 | |
| 9 | +天気08 li point pt6200 | |
| 10 | +天気09 li point pt6710 | |
| 11 | +天気10 li point pt7410 | |
| 12 | +天気11 li point pt8210 | |
| 13 | +天気12 li point pt8810 | |
| 14 | +天気13 li point pt9110 |
| @@ -0,0 +1,33 @@ | ||
| 1 | +http://stocks.finance.yahoo.co.jp/stocks/detail/?code=9984.T | |
| 2 | +銘柄コード dl stocksInfo clearFix (^\d{4}) | |
| 3 | +カテゴリ div stockMainTabParts stockMainTabPartsCurrent | |
| 4 | +業種 dd category yjSb | |
| 5 | +取得時間 dd yjSb real ^(.*)\t | |
| 6 | +銘柄名 th symbol | |
| 7 | +株価 td stoksPrice | |
| 8 | +前日比 td change \t(.*)(.*%) | |
| 9 | +前日比% td change \t.*((.*)%) | |
| 10 | +前日終値 div lineFi clearfix 0 ^([,0-9]+)\t | |
| 11 | +始値 div lineFi clearfix 1 ^([,0-9]+|-{3})\t | |
| 12 | +高値 div lineFi clearfix 2 ^([,0-9]+|-{3})\t | |
| 13 | +安値 div lineFi clearfix 3 ^([,0-9]+|-{3})\t | |
| 14 | +出来高 div lineFi clearfix 4 ^(.*?)\t | |
| 15 | +売買代金 div lineFi clearfix 5 ^(.*?)\t | |
| 16 | +値幅制限 div lineFi clearfix 6 ^(.*?)\t | |
| 17 | +時価総額 div lineFi yjMS clearfix 0 ^(.*?)\t | |
| 18 | +発行済株式数 div lineFi yjMS clearfix 1 ^(.*?)\t | |
| 19 | +配当利回り div lineFi yjMS clearfix 2 ^(.*?)\t | |
| 20 | +1株配当 div lineFi yjMS clearfix 3 ^(.*?)\t | |
| 21 | +PER div lineFi yjMS clearfix 4 ^(.*?)\t | |
| 22 | +PBR div lineFi yjMS clearfix 5 ^(.*?)\t | |
| 23 | +EPS div lineFi yjMS clearfix 6 ^(.*?)\t | |
| 24 | +BPS div lineFi yjMS clearfix 7 ^(.*?)\t | |
| 25 | +最低購入代金 div lineFi yjMS clearfix 8 ^(.*?)\t | |
| 26 | +単元株数 div lineFi yjMS clearfix 9 ^(.*?)\t | |
| 27 | +年初来高値 div lineFi yjMS clearfix 10 ^(.*?)\t | |
| 28 | +年初来安値 div lineFi yjMS clearfix 11 ^(.*?)\t | |
| 29 | +信用買残 div lineFi yjMS clearfix 12 ^(.*?)\t | |
| 30 | +信用買残前週比 div lineFi yjMS clearfix 13 ^(.*?)\t | |
| 31 | +信用売残 div lineFi yjMS clearfix 14 ^(.*?)\t | |
| 32 | +信用売残前週比 div lineFi yjMS clearfix 15 ^(.*?)\t | |
| 33 | +貸借倍率 div yjMS clearfix ^(.*?)\t |