[英]Jsoup, Selecting element is not working
Jsoup选择元素不选择div,但是孔jsoup有效但选择元素不起作用。
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView)findViewById(R.id.tb);
Button btn = (Button)findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new doit().execute();
}
});
}
public class doit extends AsyncTask<Void,Void,Void> {
String words;
@Override
protected Void doInBackground(Void... params) {
try {
Document doc = Jsoup.connect("http://www.blablabla.com/").get();
Element newsHeadlines = doc.body().getElementById("div#content");
System.out.println(newsHeadlines);
words = doc.text();
}catch (Exception e){e.printStackTrace();}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
text.setText(words);
}
}
尝试
Element newsHeadlines = doc.select("div#content");
将您的来源更改为此
public class doit extends AsyncTask<Void,Void,String> {
@Override
protected String doInBackground(Void... params) {
String words = "";
try {
Document doc = Jsoup.connect("http://www.blablabla.com/").get();
Element newsHeadlines = doc.body().getElementById("div#content");
System.out.println(newsHeadlines);
words = doc.text();
}catch (Exception e){e.printStackTrace();}
return words;
}
@Override
protected void onPostExecute(String words) {
super.onPostExecute(aVoid);
text.setText(words);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.