質問

Document doc = Jsoup.connect("http://reviews.opentable.com/0938/9/reviews.htm").get();
    Element part = doc.body();
    Elements parts = part.getElementsByTag("span");
    String attValue;
    String html;
    for(Element ent : parts)
    {
        if(ent.hasAttr("class"))
        {
            attValue = ent.attr("class");
            if(attValue=="BVRRReviewText description")
            {
                System.out.println("\n");
                html=ent.text();
                System.out.println(html);
            }
        }
    }

上記のプログラムにjsoup.jarを使用しています。

私はウェブページにアクセスしています、そして私の目的はタグ内にあるテキストを印刷することです <span class="BVRRReviewText description">text</span>.

しかし、出力として印刷されるものはありません。に追加された内容はありません String html プログラムで。だが attValue Spanタグのすべての属性値を取得しています。

どこがうまくいかなかったのですか?お知らせ下さい。

役に立ちましたか?

解決

if(attValue=="BVRRReviewText description")

あるべきです

if(attValue.equals("...")) もちろん?

これはJavaScriptではなくJavaです。

他のヒント

変化する

attValue=="BVRRReviewText description"

にとって

attValue.matches("...")

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top