0

All- I have the following code:

class AddStringTask extends AsyncTask<Void, String, Void> {    
    @Override
    protected Void doInBackground(Void... unused) {
        org.jsoup.nodes.Document doc = null;
        try {
            doc = Jsoup.connect("http://scores.espn.go.com/
                                 nfl/gamecast?
                                 gameId=320909007',%20'gamecast320909007"
                               ).get();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        docTitle = doc.select("head").first().text();
        return null;    
    }
}

I get the output "NFL Gamecast - Chicago vs Green Bay" (Green Bay won by the way). That is great but when I tried to get the actual score I could not figure out how. My problem was I was trying to replace "head" with <div id="awayScoreBox" class="vscorebox">...</div> (this is under the <Body> Tag). So following the format of using the "head" tag I tried this:

docTitle = doc.select("div id="awayScoreBox" class="vscorebox"").first().text();
return null;    

As you can imagine I got a syntax error but could not figure out why. I realize that I might have to specify that this is under the <Body> tag but I could not find any information on how to go about doing this. Any help would be greatly appreciated.

Sri Harsha Chilakapati
  • 11,744
  • 6
  • 50
  • 91
ninge
  • 1,592
  • 1
  • 20
  • 40

2 Answers2

1

It is a css selector for selecting id and class at the same time so it's

doc.select("div#awayScoreBox.vscorebox");
Community
  • 1
  • 1
gigadot
  • 8,879
  • 7
  • 35
  • 51
0

You are not escaping the quotes. You are currently using this.

docTitle = doc.select("div id="awayScoreBox" class="vscorebox"").first().text();
return null;

Change doc.select part to this.

doc.select("div id=\"awayScoreBox\" class=\"vscorebox\"").first().text();

This is why you get a SyntaxException.

Sri Harsha Chilakapati
  • 11,744
  • 6
  • 50
  • 91