Show the content of a cell table in a TextView by utilizing Jsoup

I am attempting to showcase the accumulation of snow in the last 24 hours at a ski resort using a TextView. Despite trying various methods and utilizing the CSS path, I am unable to get the TextView to display any information.

You can find the webpage here:

The CSS path I have been using is: #container > div.right > table.interior > tbody > tr:nth-child(2) > td.infoalt

private class Description extends AsyncTask<Void, Void, Void> {

    String desc;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        mProgressDialog = new ProgressDialog(Snowreport.this);
        mProgressDialog.setTitle("Snow Report");
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(false);
        mProgressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        try {
            // Connect to the web site
            Document document = Jsoup.connect(url).get();
            Elements elms = document.select("td.infoalt");
            for(Element e:elms)
                if(e.className().trim().equals("infoalt"))
                //^^^<--trim is required as,
                // their can be leading and trailing space
                {

                    TextView txtdesc = (TextView) findViewById(R.id.snowp24);
                    txtdesc.setText((CharSequence) e);


                }



            mProgressDialog.dismiss();

            } catch (IOException e1) {
            e1.printStackTrace();
        }

        return null;
    }

Answer №1

Here is the code snippet:

First, we find the element with ID "contentinterior" in the document.
From this element, we extract all tables into a list.
We then select the second table from the list.

Next, we retrieve the text content of the cell in the second row and second column of the selected table.

Answer №2

If you're facing issues with the selection parameter, it might be because you have the wrong 'String' input. To find the correct parameter for Document.select(), try inspecting the element on a webpage by right-clicking in Chrome browser.

Consider using this code snippet for better results:

final Elements tableElements = response.parse()
                    .getElementsByClass("info")
                    .select("td");

for (Element element : tableElements) {

    String string = element.getElementsByClass("infoalt").text().trim()

    Log.d("Jsoup", string);

}

Wishing you success and happy coding!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A website with two distinct pages, where only the first page is refreshed

I have split the content of my HTML page into 2 separate subpages, based on the references provided below: Multiple distinct pages in one HTML file This is how my code is structured: ... <script> function show(shown, hidden) { document.getEle ...

What is the best DOCTYPE declaration to implement?

After exploring various resources on DOCTYPE declaration and its variations - strict, transitional, and frameset, I am still struggling to grasp their distinctions. The specific confusion lies in understanding the variance between strict and transitional d ...

Is there a way for me to position my menu on the right side of my website?

I am currently working on a gallery website and facing an issue with the menu placement. I want to position the menu items on the right side of the images, but they keep appearing at the bottom instead. Despite adjusting the width in classes like galleryme ...

How can I ensure that my background image always stretches to full width, no matter how small the site format becomes in CSS?

I'm currently working on making my website responsive, but I'm encountering an issue. When the website width gets smaller, the background doesn't take up the full width as intended. I've tried various methods to address this problem, bu ...

Arrange the footer content into multiple columns

Hello! I'm currently working on creating a footer for my website. I've written this code and everything seems to be functioning correctly, except for the fact that the second row is positioned under the first row and taking up half of the bottom ...

Embracing right-to-left (RTL) languages

I am looking to create a website that can support both left-to-right (LTR) and right-to-left (RTL) languages seamlessly. My goal is to have the text direction switch automatically to RTL if the content is in an RTL language. Additionally, I want the input ...

Using jQuery to load form elements in web development

Can jQuery's .load() function load <form> elements? I noticed that it appears to be removing them. Here is an example of my code: $('<div></div>').load($link.attr('href') + ' #divDlgContent', function( ...

Tips for retrieving the option text value following an onchange event in AngularJS

Whenever I change the selection in my dropdown menu for 'Cities', the alert is displaying the value of the previous selection instead of the current one. For example, if I select a state and then switch to Cities, the alert shows the text related ...

I'm having trouble getting the npm install for classnames to work within my li tag

I need some help with React JS. I'm attempting to merge my classes using the npm package called classnames. https://www.npmjs.com/package/classnames However, I'm encountering an issue: classnames doesn't seem to be working as expecte ...

Exploring IP geolocation integration within Rails 3

I am looking to add a dynamic feature to my homepage that will display the location object closest to the reader's physical location. Currently, I have a Location model with longitude and latitude fields. My goal is to retrieve the location model obj ...

Issue encountered in SQL PHP form script at line 23

I'm currently working on some code to insert data into different tables, but there seems to be an issue on line 23. This code is part of a college project registration form. <?php $con = mysql_connect(","",""); if (!$con) { die('Could not c ...

Challenges encountered on Chrome browser when using label:hover along with relative positioning

Currently, I am in the process of creating a price list for a section of a website I'm developing. To make it interactive, I am utilizing checkbox type inputs along with labels so that users can select the services they desire, and the webpage will au ...

Each ListView item will display a TextView on the left side and the number of contents on the right side, showcasing the specific details within

When it comes to ListViewitem, I'm looking to arrange a TextView on the left end and the number of contents on the right end for each particular item. For example, if I have the items jj, kk, ll in a list with 3, 4, 5 contents respectively, I would li ...

The event listener is failing to trigger the JavaScript function upon click

I am experiencing an issue with an onClick listener triggering an AJAX call to a PHP script. It seems that the click is not being recognized. Any suggestions on what could be causing this? Index.html <html> <head> <script src="//ajax.googl ...

How to eliminate a line break following an image tag in HTML

Before I display my image with an H3 tag, I didn't use any break statements. However, the two tags are appearing on separate lines when I view it in the browser. Is there a CSS trick I can use to solve this issue, or perhaps an easier tag attribute th ...

Contrary information found on Developer Sites regarding the use of shouldOverrideUrlLoading in webview

Many Android developers choose to implement their own webview component. Despite the numerous discussions on this topic on stackoverflow, there still seems to be a lack of clarity surrounding it. In order to handle opening links within a WebView, Android ...

Display HTML content using JavaScript only when a checkbox is selected

Currently, I am updating an HTML form to show additional subsets of questions based on the selection of a "parent" checkbox. The current implementation works well, but I am wondering if there is a more efficient way to achieve this without having to rewrit ...

Help with Crafting Responsive CSS Design

I am seeking help to better comprehend the concept of responsive design through this question. Let's imagine a header on a standard desktop screen. Within that, I have a div element containing the information I wish to showcase. .hdrinfo{ width: ...

What is the best way to create a drop-down menu that exports data directly to an Excel spreadsheet?

I have been struggling with a seemingly simple issue - I can't seem to get my drop-down box to display the chosen option. The code I'm using is quite similar to this generic one, but for some reason, it's not reporting the selected option to ...

Building RESTful API requests on Android with Node.js

I have developed a RESTAPI using Node.js and I am attempting to call it from my android application. However, I am facing issues with making the request to the Node.js Rest API. The code snippets are as follows: Node.js var restify = require('rest ...