0

この文字列を Web サイトから解析して識別し、色を変数に格納します (緑が値 0 を割り当てるか、それ以外の場合は 1 とします)。

<tr><td class="mapbuttons" align=right>
<a href="http://www...."><font color=green>TEXT <font color=#ff8000>(2)</font>3/14</font></a>

このデモコードを見つけました:

import java.net.*;
import java.io.*;
public class WebSiteReader {
  public static void main(String args[]){
       String nextLine;
       URL url = null;
       URLConnection urlConn = null;
       InputStreamReader  inStream = null;
       BufferedReader buff = null;
       try{
          // Create the URL obect that points
          // at the default file index.html
          url  = new URL("http://www.yahoo.com" );
          urlConn = url.openConnection();
         inStream = new InputStreamReader( 
                           urlConn.getInputStream());
           buff= new BufferedReader(inStream);

       // get the values I want here

     } catch(MalformedURLException e){
       System.out.println("Please check the URL:" + 
                                           e.toString() );
     } catch(IOException  e1){
      System.out.println("Can't read  from the Internet: "+ 
                                          e1.toString() ); 
  }
 }
}

1) 正しいですか?つまり、コメントを、私が望むことを行うコードに置き換える必要がありますよね? 2)私はJavaが初めてなのでコードとテキストで「遊ぶ」方法を手伝ってもらえますか?

4

1 に答える 1

2

JSoupを使用してハードワークを実行します(HTMLを解析します)。そこにあるものの多くは壊れたHTMLであるため、HTMLを解析するのは本当に難しいです。

以下に似たもの(少しでもテストされていない場合は、最初のフォント要素を選択し、color属性の値を抽出する必要があります。

Document doc = Jsoup.connect("http://www.yahoo.com").get();
Element fontTag = doc.select("font").first();
string theColor = fontsTag.attr("color");
于 2012-04-19T11:02:08.270 に答える