Exploring an array within an API using Puppeteer

I have been attempting to access an array from an API

My attempt involved using the following code snippet: const names_2 = await page.evaluate(() => Array.from(document.querySelectorAll('.mainDiv > Departure'), Departure => Departure.innerText));

Unfortunately, my efforts have not yielded successful results

Below is the input I provided:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch()
  const page = await browser.newPage()
  await page.goto('http://xmlopen.rejseplanen.dk/bin/rest.exe/multiDepartureBoard?id1=8600646&format=json')

    const result = await page.evaluate(() => {
      let temperature = document.getElementsByTagName("pre")[0].innerText;
temperature = JSON.parse(temperature);
    return {
        temperature
      }
  })

  console.log(result)


})()

This is what I received as output:

{
  temperature: {
    MultiDepartureBoard: {
      noNamespaceSchemaLocation: 'http://xmlopen.rejseplanen.dk/xml/rest/hafasRestMultiDepartureBoard.xsd',
      Departure: [Array]
    }
  }
}

Answer №1

Your current approach does not seem logical. It would be more efficient to simply request the data

const rq = require('request-query');
rq.get({
    url: 'http://travelinfo.querytool.com/bin/response.exe/travelBoard?id=8600646&format=json',
    json: true
})
    .then(result => result.TravelResponse.Departures)
    .map(item => console.log(item))
;

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

Fixing the issue with animated scrolling in React Native's Flatlist component

I attempted to customize the default refresh indicator for a Flatlist in React Native. My goal was to create something similar to Snapchat, Instagram, or the default iOS refresh indicator instead of the unattractive Android indicator. This is what I tried: ...

Develop a custom function to determine if every element within the array is identical

Issue I am currently working on a function that evaluates an array to determine if all elements inside the array are identical. If they are, it should return true; otherwise, it should return false. However, I do not want the function to return true/false ...

Getting values from ng-repeat input/checkboxes upon form submission in AngularJs

Here's a form with input fields and check boxes that repeat: <form class="form-horizontal popupform" novalidate> <input type="text" data-ng-model="returns.altCity"> <input type="text" data-ng-model="returns.altZip"> < ...

Is it possible to use a += operator with attr() and val() functions in JavaScript?

Ever since I switched to jQuery, my development process has significantly sped up. However, there is one task that has become a bit more time-consuming: appending a string to an attribute or value. For instance, if you wanted to add a letter to the value ...

When users click on the tiles, they will act as interactive objects that will direct them to a different page within the Angular framework,

output Here is the code for my app component: <H1>AI API DEMOS</H1> <div> <ul> <li class="active"><a routerLink="/market">Market Size</a></li> <li role="presentation&qu ...

The data being retrieved from the controller in AngularJS is not displaying as expected

Just started learning AngularJS. Currently following this MEAN Stack Intro: Build an end-to-end application Created a basic html file to test angularjs. index.html <html> <head> <meta charset="utf-8"> <title> ...

Leveraging context and hooks in React JS

Once again, I find myself here. Just 3 hours ago I was struggling with understanding how to use Context and useState in React. Thankfully, I managed to solve that issue on my own. However, now I'm facing another challenge - this time it's about s ...

Investigating Javascript compatibility problems with Firefox 4

In FF3.X and IE7 to 9, the code below is functioning correctly, but in FF4, there seems to be an issue. The following code is used in two different locations within my file: var args = "method=getoptions"; args += "&dr ...

Efficiently managing desktop and mobile pages while implementing lazy loading in Angular

I am aiming to differentiate the desktop and mobile pages. The rationale is that the user experience flow for the desktop page involves "scrolling to section", while for the mobile page it entails "navigating to the next section." The issue at hand: Desk ...

Can Object Oriented Approach combined with Graph Theory Algorithms outperform traditional array-based manipulations in Java?

When I tackle Graph Theory problems, I tend to create multiple classes like these: class Node{ ...... } class Edge{ ...... } This often leads to performance and speed issues. This has me thinking - is using arrays to store graphs faster than using ...

Using jQuery to manipulate HTML elements that are dynamically loaded via ajax

Currently, I am enhancing my basic HTML tables with the help of the jQuery plugin called DataTables. The following code allows me to load the DataTables plugin for all pages: <script> $(document).ready(function() { $('table. ...

After installing the latest version of [email protected], I encountered an error stating "Module 'webpack/lib/node/NodeTemplatePlugin' cannot be found."

Upon updating to nextjs version 10.1.3, I encountered an error when running yarn dev. Error - ./public/static/style.scss Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin' Require stack: - /path_to/node_modules/mini-css-extract-plugi ...

Can a native intent be triggered from an app enclosed within PhoneGap on Android?

Currently, I am in the process of creating an application using Sencha Touch 2.0.1 & PhoneGap. My main challenge is finding a way to capture and transfer events that are triggered within Sencha Touch to the native Android environment. For instance, th ...

Avoid binding an object in Vue.js when you intend to copy it to a different data attribute

I am facing a situation where I have an object retrieved from my API and need to replicate it to another object while loading a modal. The following method achieves the duplication: this.servicesForm.services = this.team.services; // New object ...

The ng-repeat directive is displaying only the final item from the JSON data

Is it possible to customize the number of items displayed from a JSON file using ng-repeat in AngularJS? Currently, it only shows the last item. JSON Data { "list":{ "item1": { "id":1, "img": "1.jpg", "u ...

Step-by-step guide on incorporating a climate clock widget into your Angular project

Is there a way to integrate the Climate Clock widget from into my Angular project? Upon adding the following code snippet: <script src="https://climateclock.world/widget-v2.js" async></script> <script src="https://climateclo ...

Setting a variable before a debounced method function in Vue: Tips and tricks

Is there a way to set isLoading = true prior to the function being executed? Currently, isLoading remains false until the debounced function is triggered. <script> import _ from 'lodash' export default { data: { isLoading: false; ...

Warning: The function is missing a dependency in the React Hook useEffect

Currently, I have a React component that utilizes the useEffect() hook: const [stateItem, setStateItem] = useState(0); useEffect(() => { if (condition) { myFunction(); } }, [stateItem]); const myFunction = () => { return 'hello&apos ...

Guide to activating a reaction following an occurrence in a React component

I have started developing a React application that loads blog posts along with their associated comments. The challenge I am facing is how to trigger a refresh of the comments component and display the new comment immediately after it has been submitted. ...

Error: The function RFB is not defined

Trying to set up a VNC client using AngularJS (tutorial link here), but encountering an error while running the application: TypeError: RFB is not a function Below is the server.js code snippet: var RFB = require('rfb2'), io = require(&apos ...