Reputation: 89
The problem I am having is that I am trying to parse this website but I am getting thiserror . I am new to Jsoup and not quite sure whats making the error. Is there a way to stop parsing on certain element like if i want it to stop on first instance of Bobby? (row : Cindy : Mike : Bobby). Thanks in advance!
import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.os.StrictMode.ThreadPolicy;
import org.jsoup.Jsoup;
import java.io.IOException;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class tableScreen extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.table);
takeTable();
}
public static int SDK_INT = android.os.Build.VERSION.SDK_INT;
public void takeTable()
{
Document doc = null;
if (SDK_INT >= 10)
{
ThreadPolicy tp = ThreadPolicy.LAX;
StrictMode.setThreadPolicy(tp);
}
try{
doc = Jsoup.connect("http://www.htmlgoodies.com/tutorials/tables/article.php/3479851").get();
System.out.println("1");
Element containingDiv = doc.select(".body").first();
System.out.println("2");
Elements table = containingDiv.select("table");
System.out.println("3");
Elements rows = table.select("tr");
System.out.println("4");
for (Element row : rows)
{
System.out.println("row: "+row.child(0).text()+" : "+row.child(1).text()+" : "+ row.child(2).text());
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
Upvotes: 1
Views: 317
Reputation: 89
OK guys I manage to fix it ,
doc = Jsoup.connect("http://www.htmlgoodies.com/tutorials/tables/article.php/3479851").get();
Element containingDiv = doc.select("table").first();
Elements table = containingDiv.select("tbody");
Elements rows = table.select("tr");
Upvotes: 1