gpt4 book ai didi

java - Jsoup,选择元素不起作用

转载 作者:行者123 更新时间:2023-12-02 13:25:11 25 4
gpt4 key购买 nike

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);

}
}

最佳答案

将您的来源更改为此

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);

}

}

关于java - Jsoup,选择元素不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43409335/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com