Difficulty in displaying YQL JSON Results with HTML/JavaScript

When utilizing the subsequent YQL query along with XPATH to retrieve data from certain elements on a webpage:

select *
from html 
where url="http://www.desidime.com" 
and 
xpath='//h5[@class="product_text"]'

I am attempting to showcase the outcomes on a basic HTML page, yet for some reason it is not functioning as expected. It seems like there might be a simple mistake somewhere.

Below is the code included in my HTML page:

<html>
<head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding">
    <style type='text/css'>
        #results {
            width: 40%;
            margin-left: 30%;
            border: 1px solid gray;
            padding: 5px;
            height: 200px;
            overflow: auto;
        }
    </style>
    <script type='text/javascript'>
        // Parses returned response and extracts
        // the title, links, and text of each news story.
        function top_stories(o) {
            var output = '';
            var items = o.query.results.h5;
            var no_items = items.length;
            for (var i = 0; i < no_items; i++) {
                var title = items[i].a.content;
                output += "<h3>" + title + "</h3><hr/>";
            }
            document.getElementById('results').innerHTML = output;
        }
    </script>
</head>
<body>
    <!-- Div tag for stories results -->
    <div id='results'></div>
    ishan1
                <!-- The YQL statment will be assigned to src. -->
    <script src='https://query.yahooapis.com/v1/public/yql?q=select%20*%0Afrom%20html%20%0Awhere%20url%3D%22http%3A%2F%2Fwww.desidime.com%22%20%0Aand%20%0Axpath%3D\"%2F%2Fh5%5B%40class%3D%22product_text%22%5D\"&format=json&callback='></script>
</body>
</html>

Your assistance in resolving this matter would be greatly appreciated.

Answer №1

It appears that there was an issue with the encoded XPath query you provided. Upon attempting to access the URL in my browser, I encountered an error. I recommend replacing it with the following link, as this resolved the error and allowed me to receive valid JSON data:

https://query.yahooapis.com/v1/public/yql?q=select+*+from+html+where+url%3d%22http%3a%2f%2fwww.desidime.com%22+and+xpath%3d%27%2f%2fh5[%40class%3d%22product_text%22]%27&format=json&callback=

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

The error message "Type 'string | number' is not assignable to type 'number'" indicates a type mismatch in the code, where a value can be either

I encountered an error code while working with AngularJS to create a countdown timer. Can someone please assist me? //Rounding the remainders obtained above to the nearest whole number intervalinsecond = (intervalinsecond < 10) ? "0" + intervalinseco ...

What is the best way to incorporate an exported TypeScript class into my JavaScript file?

One of my JavaScript files is responsible for uploading a file to Microsoft Dynamics CRM. This particular JavaScript file makes use of RequireJS to reference another JavaScript file. The referenced JavaScript file, in turn, was compiled from multiple Typ ...

How to include a new value in a JSON file with Ruby

Hey there! I have a code snippet that generates a JWT token from a private key. What I'm trying to achieve is converting the token into a JSON object. The current implementation successfully creates the token, but I'm struggling to format it as ...

Get an array of JSON values using a jQuery function

How can I create a jQuery function that imports a JSON value and returns an array when called? I have written the following function, but it is returning an empty array. The JSON file I am working with is very basic, similar to this example: { "fruit": [ ...

Authentication - The success callback of $http is executed rather than the error callback

I seem to be facing an issue with authentication in a MEAN stack app, possibly due to my limited understanding of promises and the $http's .then() method. When I try to authenticate to my backend Node server with incorrect credentials, the success cal ...

Encountered a problem while parsing an XML file using JavaScript from an external server

Currently, I am developing an iPhone application in HTML that needs to pull content from an XML file stored on a remote server and display it in a list. I have successfully accomplished this task when the XML file is hosted on the same server using the fo ...

What causes a browser to redirect when trying to update the value of the alt field in a Wordpress media image?

Attempting to create a bookmarklet for the Wordpress image gallery manager that triggers the sidebar when an image is clicked. The sidebar contains fields for alt text (input), legend, and description (both textarea). <a href="javascript:var t=document ...

File handling in Angular 2 using Typescript involves understanding the fundamental syntax for managing files

Would someone be able to explain the fundamental syntax for reading and writing text files, also known as file handling in TypeScript? If there is a corresponding link that anyone could provide, it would be greatly appreciated. ...

"Error: The functionality of finding places on Google Maps is not

I've encountered an issue while trying to integrate Google Maps into my Node application. The map is loading correctly and I'm able to retrieve my location. However, I am facing a problem with implementing the Google Places API code to allow user ...

The Skeleton-Avatar and ImageButton components in MUI React have had their backgrounds reshaped into perfect ovals

I am facing an issue with the mui Stack where all the background shapes of the Skeleton Avatar and background area are turning into oval or ellipsoid shapes. I have tried setting equal width and height for Avatar but it has not solved the problem. Is ther ...

Converting arrays of different lengths into objects using the even and odd indices in JQuery

In need of a solution to transform sets of arrays based on odd or even indexes with varying array lengths. My challenge is organizing and adding additional arrays correctly to the respective children arrays, which should be determined by the index parity. ...

Repeating every other item in a list using ng-repeat in AngularJS

Using AngularJS version 1.5.3 In my view, I have a list of items that I want to display. After every two items, I would like to show a new div below the first one. <div class="col text-center" ng-repeat="event in weekDay.events"> &nbsp;& ...

Running the command "nexrjs create next-app" successfully generates all the necessary directories for the

After trying to install NextJS using both methods npm install next react react-dom and npx create-next-app appname, I noticed that my project directories are different from what they are supposed to look like: Instead of having pages, api(_app.js, index.j ...

Automatically populate the SharePoint list with new items from parsed JSON if they are not already included

Currently, I am facing a challenge with two lists. One list contains 8 items that are stored in a parsed JSON format, while the other list is a Sharepoint list consisting of only 3 items retrieved from the Classes List. Both lists share a unique ID for eac ...

The `<Outlet/>` from react-router is being rendered in a location outside of its intended wrapper div

Utilizing MUI for crafting a straightforward dashboard featuring an <AppBar>, a side <Drawer>, my component appears as follows: <> <AppBar> // code omitted <AppBar/> <Drawer> // code omitted <Drawer/> / ...

Dynamic Form Submission - Displaying Notifications for Success and Failure

While I have managed to successfully submit my form using PHP, I am currently facing some challenges with AJAX. Whenever I submit the form, an error message pops up as if 'res' is false instead of true. Despite my efforts to troubleshoot and rese ...

Using JavaScript to browse and filter by category

After spending some time working on a search function, I received some assistance from Tim Down who provided me with a simple code to search for specific text within a page. Now, my goal is to modify the code to enable searching by category. I have struct ...

Exploring the depths of JSON

After requesting data from my server, I received the following dataset: {"success":"y","carrier":"Verizon Wireless","isMobile":"true"} Upon attempting to parse the JSON result returned from my ajax function $.ajax( { url: 'php/lookup.php', ...

When the Add button in AngularJS is clicked, a new popup page should appear by concealing the parent page

I am currently working on a project that involves using the AngularJS/Breeze framework within the HotTowel Template. One of the requirements I have is to include a button/link labeled "Add" on the parent.html page. When this button is clicked, it should t ...

Unable to store user data in the MongoDB Database

I'm currently facing an issue while trying to store user information in my MongoDB database. Everything was working fine until I implemented hashing on the passwords using bcrypt. After implementing password hashing, I am encountering difficulties in ...