Examining the JavaScript file for integration into a Java application

Currently, I am utilizing jsoup for parsing HTML content from a website. The issue I am facing is related to two option lists that are generated dynamically from a multidimensional array within a JavaScript file. Due to the dynamic nature of these lists, jsoup is unable to parse the results in HTML. However, all the necessary data can be found in the JS file. My objective is to periodically load this file and store or update the array data from it into a local database within an Android application. The specific JS file involved can be accessed through this link: here. For reference, the webpage showcasing the lists can be viewed here: here. Is there a viable method to selectively download certain parts of this file for manipulation in Java, similar to handling a DOM in HTML?

Answer №1

If you want to incorporate JavaScript functionality into your Android app, there are different approaches you can take. One option is to use a WebView with a JavascriptInterface, while another alternative involves using the Rhino engine provided by Mozilla.

To implement the Rhino approach, start by downloading the Rhino library (version 1.7.7.1) from the official source.

After downloading the Rhino jar file (e.g., rhino-1.7.7.1.jar), move it to the libs folder within your Android project directory.

Next, add the following dependency to your build.gradle (Module: app) file:

dependencies {
    [other dependencies]
    compile files('libs/rhino-1.7.7.1.jar')
}

The sample activity provided below demonstrates how to load a script file, modify the script based on comments, and execute functions to populate arrays. These arrays are then retrieved and stored as Java arrays:

MainActivity.java

// Code for MainActivity class goes here

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

Tips for avoiding the display of concealed forms on a webpage

Hey there, I'm just starting out with html forms and currently experimenting with Jquery to hide forms upon loading the page. However, I've encountered an issue where some forms briefly appear before hiding after the page finishes loading. Here& ...

Capture images on Android with Camera 2 API without saving EXIF data

I recently created a CameraActivity using the Camera 2 API for Android. However, I noticed that all the photos I take are missing EXIF information, such as geo-position data. Despite trying to access the GPS position through ExifInterface, I have not been ...

Having trouble accessing the 'checked' property of the checkbox

I've been developing a web application using Vite, JavaScript, jQuery, and Bootstrap. I'm facing an issue where the jQuery .is(':checked') function is not working as expected on one specific page. Despite the checkboxes being checked, t ...

How to iterate through a "for" loop in JavaScript using Python-Selenium?

In my current project, I am utilizing Javascript to gather data from an HTML page using Selenium. However, I am facing a challenge where I am unable to execute the multi-line for loop in the Javascript portion on my computer through Selenium with Python (S ...

Incorporating Google Maps API v2 within a fragment: A step-by-step guide

I have encountered an issue where I am trying to add a Google API into an action bar that goes to a fragment. Unfortunately, it failed because the fragment class needs to extend FragmentActivity, while the action bar does not allow it. Can someone please h ...

Error: The requested resource /test.html cannot be found. This issue is related to

Currently facing challenges while setting up my development environment for learning Angular.js, following the instructions in Pro Angularjs. Despite researching solutions to similar issues encountered by others, I am still unable to resolve the problems. ...

Ways to ensure continuous execution of GUI function calls without compromising responsiveness

I have a creative animation idea involving horizontally aligned arrow heads with changing alpha values to create an animated effect. For example, starting with the first arrow at alpha 1.0, then gradually decreasing the alpha value for each subsequent arro ...

Potential reasons for the malfunction of the bootstrap 5 navbar dropdown

After copying the code for the navbar dropdown from Bootstrap 5 documentation, the dropdown feature is not functional. Clicking on the dropdown does not display the links ("action", "another action", "something else"). What steps should I take to troublesh ...

How to dynamically add multiple classes in Vue.js

I want to add multiple classes when the user clicks on an item. Currently, I have this code snippet: <div :class="[ item === form.score ? 'text-black bg-white': '' ]" @click="form.score = item" v-for="item in 10"> {{ i ...

What is the purpose of including the 'return false;' statement in a submit event?

I am curious about the purpose of the return false; statement within this Pig-Latin translator. When I remove it, I notice that the translation automatically disappears without any delay, but I'm uncertain about the underlying mechanism causing this b ...

Dynamic AngularJS data model

Custom Directive Code (function() { 'use strict'; angular .module('app.colorslider.directive', []) .directive('colorSlider', [ '$timeout', '$rootScope', ...

Exploring the applications of the `this` keyword within a jQuery-based JavaScript object

Recently, there has been a challenge in creating a JavaScript object with the specific structure outlined below: function colorDiv(div){ this.div=div; this.div.bind("click",this.changeColor) this.changeColor(){ this.div.css(" ...

Execute a script for each DOM alteration and user interaction

I have a unique feature on my website that involves a backbone-powered player fixed at the bottom of the page. This player is capable of playing a list of songs, and users can click on "Play" for any album or song while navigating different pages on the si ...

Implementing text assignment to a textbox field using React Redux

element: MainInput: ); } After successfully fetching student data from the database, I encountered an issue while trying to display the information in a textbox React Field. Even though this.props.firstname displayed the correct value on th ...

Generate the entity and then transfer the data into an array

I am dealing with multi-level hierarchies that need to be displayed in a select list. Once the user selects values from the table column, they should be able to filter by clicking on the column. var name = ['Akansha', 'Navya']; var age ...

What causes my Bootstrap 5 popover to no longer open on focus when I reopen the modal it is attached to?

I am facing an issue with my Bootstrap 5 modal and the popovers that are attached to it. On hovering over a button in my HTML, a popover appears asking 'Are you sure?' and instructing the user to click the button to proceed. Clicking the button ...

Struggles with integrating a disappearing navigation bar when scrolling - JavaScript

I've been struggling with a fixed position navbar on my blog and I'm attempting to incorporate basic JS to hide the navbar while scrolling down and have it reappear when scrolling up. You can find the code snippet I'm trying to implement in ...

Error encountered with AJAX call when attempting to utilize string method

I am looking to add HTML content to a TinyMCE editor in an ASP.NET MVC project. After some thought, I have found a solution that involves converting the HTML file to a string on the server side and then calling it using Ajax on the client side. Here is a ...

In JavaScript, I'm facing an issue where I can't seem to use ' ' for line breaks for some reason. It's not functioning as expected, and I'm

It seems that I have been struggling with writing a new line in my code using "\n". Despite multiple attempts, the desired outcome has not been achieved. Below is my source code along with a screenshot of the result: var ary3 = new Array('seve ...

Sorting an ArrayList by data retrieved from a SQLite database

I am working on an Android project where data is being added to a database. I want to sort the ArrayList alphabetically. Can someone please assist me with this? import android.content.ContentValues; import android.content.Context; import andro ...