0

I'm trying to parse (with jsoup) some specific text from a website, but it doesn't work for me. LINK TO SITE

It's the number "43" in red text that I am interested in at the top-right of the page.

This is what I tried:

String test;

public void scan(String url) throws Exception {

    Document document = Jsoup.connect(url).get();        
    Elements votes = document.select("#malicious-votes .pull-right");
    test = votes.text();
}

public int returnVotes(){
    return test();
}

~ ~ ~

public static void main(String[] args) throws Exception {

    Scan_VirusTotal virustotal = new Scan_VirusTotal();     
    virustotal.scan("https://www.virustotal.com/sv/url/cbf2d00f974d212b6700e7051f8b23f2038e876173066af41780e09481ef1cdd/analysis/1407146081");      
    System.out.println(virustotal.returnVotes());

This prints nothing. Other elements work fine with this exact method, so I'm really confused as to why this particular piece of text won't parse.

Ideas? Thanks.

EDIT - added some HTML from page as requested:

<div style="display:block" class="pull-right value text-red" id="malicious-votes">44</div>
3
  • Please provide some sample HTML instead of posting a link to the website in question. Commented Aug 4, 2014 at 12:30
  • Just linking to the page shows nothing of what source you are actually looking at, thus you should always include the code instead of only linking. Commented Aug 4, 2014 at 13:15
  • Well I explained which part I was referring to. If you click inspect code it will take you straight to the relative code. The reason why I didn't include is because the tree is quite big and so I didn't want to cut anything out :) Commented Aug 4, 2014 at 13:24

2 Answers 2

2

Try using this instead:

Elements votes = document.select("#malicious-votes");
test = votes.text();

I tried this $("#malicious-votes .pull-right") in the browser console of the given page, gives me empty array. But $("#malicious-votes") gives me the vote div which itself has the class pull-right.

Sign up to request clarification or add additional context in comments.

Comments

2

Your selector should be:

"#malicious-votes", not "#malicious-votes .pull-right".

"#malicious-votes .pull-right" selects any elements with class pull-right that are descendants of #malicious-votes. What you want is the #malicious-votes element itself.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.