Answer the question
In order to leave comments, you need to log in
How to parse an element by its class?
I am writing a parsing script using Jsoup
With the code title = doc.title();
The title is parsed perfectly.
But I'm writing code:
an error appears:
And for some reason org.jsoup.nodes is not used.title = doc.getElementsByClass("Класс элемента");
class MyTask extends AsyncTask<Void, Void, Void> {
String title;
EditText search=(EditText)findViewById(R.id.Ewo_InputSearch);
String Name = search.getText().toString();
@Override
protected Void doInBackground(Void... params) {
Document doc = null;//Здесь хранится будет разобранный html документ
try {
//Считываем заглавную страницу http://harrix.org
doc = Jsoup.connect("https://www.site.ru/site_search#args:ajax=1&queryfr="+Name+"").get();
} catch (IOException e) {
//Если не получилось считать
e.printStackTrace();
}
//Если всё считалось, что вытаскиваем из считанного html документа заголовок
if (doc!=null)
title = doc.getElementsByClass("ss_search_bx_list_title");
else
title = "Ошибка";
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
textView.setText(title);
//Тут выводим итоговые данные
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question