문제

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);
            }
        }
    }

Am using Jsoup.jar for the above program.

I am accessing the webpage and my aim is to the print the text that is found within the tag <span class="BVRRReviewText description">text</span>.

But nothing is getting printed as output. There is no contents added to the String html in the program. But attValue is getting all the attribute values of the span tag.

Where must I have went wrong? Please advise.

도움이 되었습니까?

해결책

if(attValue=="BVRRReviewText description")

should be

if(attValue.equals("...")) surely?

This is Java, not Javascript.

다른 팁

Change

attValue=="BVRRReviewText description"

for

attValue.matches("...")

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top