N
N
Newmo2017-08-09 15:47:13
Java
Newmo, 2017-08-09 15:47:13

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("Класс элемента");
8b30fedc1c2b422ea1e2c3dca1096ce0.jpg
95b04c362e59451fa437f7f9cdd4415e.jpg

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);
            //Тут выводим итоговые данные
        }
    }

Tell me, what's the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
al_gon, 2017-08-09
@Newmo

Your titel is String, but getElementsByClassreturns a collection of elements org.jsoup.select.Elements
that match the criteria, in this case class .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question