0
我遇到了使用JSOUP for android解析標記的問題。我一直試圖在文檔中進一步下去,該應用程序無法正常工作。請幫忙。我得到了「TR」來解析TR中的所有數據,但我想抓取一個元素並解析到Toast框。使用JSOUP爲android應用程序解析數據
謝謝
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class JsoupTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button myButton;
myButton = (Button)findViewById(R.id.button1);
myButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
try {
Document doc = Jsoup.connect("http://money.cnn.com/data/bonds/").get();
Elements divs = doc.select("td.login.div.status");
for (Element div : divs) {
Toast toast = Toast.makeText(getApplicationContext(), div.text(), Toast.LENGTH_LONG);
toast.show();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}
請描述問題? –