Utilizing PhantomJS for efficient scraping of web pages with simultaneous data loading

My current challenge involves scraping a page with PhantomJS: . The goal is to extract the links of all products listed on the page. However, new data is loaded dynamically as I scroll down, adding 12 new items each time.

I discovered a hidden form within the HTML code that allowed me to retrieve 61 elements out of a total of 110 when submitted.

The question now is, how can I obtain the links of all products?

Below is the code snippet I have been working on:

var system  = require("system");
var fs      = require("fs");
var path = 'productLinks.txt';
var url = "http://www.avrilgau.com/fr/5-chaussures";
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
 console.log(msg);
};

page.open(url, function (status) {

var content = page.evaluate(function()
 {
  var allUrl=[];

  var tempNodeArray =document.querySelectorAll("#content > ul > li > div > div a.img");

  for (var i = 0; i < tempNodeArray.length; i++) {
    allUrl.push((tempNodeArray[i]).href);
  };

  return allUrl.join("\n")+"\n";


 });

console.log(content);
fs.write(path, content, 'a');

phantom.exit();

});

Answer №1

I have noticed that there are exactly 61 products listed in the specified category. The infinite scroll feature seems to stop displaying products after reaching this count, as intended by the site's design. Can you please clarify where the number 110 came from?

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

Which JavaScript library or template engine would be most suitable for this scenario?

I am tasked with creating an invite your Facebook friends module that will display the names and photos of your friends, allowing you to message them. It is essential that this feature seamlessly integrates into my website's design, so I need to style ...

Update a JSON value using an MUI Switch element

I am currently developing a feature that involves toggling the state of an MUI switch based on API responses. The status of the Switch is determined by the Active field in the API response. If the JSON field is 1, the switch is turned on, and if it's ...

Transferring Information between a Pair of Controllers

Currently, I am utilizing angular version 1.x and faced with the challenge of sharing data between two controllers. In my mainctrl, I am working with the above model. The radiotmplt.radiohead=='IRU600v3' is utilized in firstctrl. Unfortunately, ...

“The asynchronous wicket task”

I am facing an issue on my webpage where I have multiple select lists with a large number of values being populated from a database. Given the limitations in optimizing the database, I am exploring options within Wicket or through AJAX to asynchronously lo ...

Troubleshooting Issue with Mongoose Virtual Field Population

I am currently facing an issue with my database due to using an outdated backend wrapper (Parse Server). The problem arises when dealing with two collections, Users and Stores, where each user is associated with just one address. const user = { id: &q ...

RN TypeScript is handling parameters with an implicit any type

My React Native (RN) application includes the following code snippet: handleTextChange = e => { this.setState({ value: e }) } I am using TypeScript (TS) and it's giving me a warning saying, "parameter 'e' implicitly has 'any&apos ...

What are the steps to reset a JavaScript game?

I'm currently working on a JavaScript game project. Once the game is finished, I'd like to give players the option to go back to the main menu by clicking a button, then start a new game by clicking play again. However, I've run into an issu ...

I have run into a roadblock when trying to generate dynamic pages with Gatsby

Utilizing Gatsby in my current project, I am attempting to implement pagination on a specific page. Following the instructions provided at https://www.gatsbyjs.org/docs/adding-pagination/ and this additional resource , but encountering issues. In my gatsb ...

Creating directional light shadows in Three.JS: A Step-by-Step Guide

Can shadows be generated using a DirectionalLight? When I utilize SpotLight, shadows are visible. However, when I switch to DirectionalLight, the shadow functionality doesn't seem to work. ...

React element failing to appear on webpage

I'm having trouble loading the snippetInfo.js file in the HTML, and I can't seem to figure out why. I've searched online extensively for solutions, but none of them have worked for me. Whenever I try adding type='text/javascript' t ...

Tips for resolving the error message "Cannot assign type 'string' to type '...' in NextJS"

In my nextjs-app, there is a Button component implemented as follows: interface IButton { text: string theme: 'primary' | 'secondary' size: 'small' | 'medium' | 'large' onClick?: () => void } ...

Utilizing nprogress.Js for a Dynamic Progress Bar

I'm trying to create a progress bar similar to the one on YouTube using the nprogress.js plugin. However, I want the progress to start from the middle of the page, like this: start | --------------------------------------------> | end Instead of: ...

Detect if the user is using Internet Explorer and redirect them to a different

My web application is having trouble rendering in Internet Explorer. In the meantime, I would like to detect if the user is using IE and redirect them to a different page specifically for IE visitors. What is the best way to accomplish this? Should I use ...

Angular: Monitoring changes in forms

Currently, I am working on developing an Angular application where I need to monitor any changes in the form and execute specific operations based on those changes. While I am aware that this can be done using $scope.watch, I am concerned about the impact ...

Ways to store data in the localStorage directly from a server

I'm facing an issue - how can I store data in localStorage that was received from the server? Should I use localStorage.setItem for this purpose? And how do I handle storing an array in localStorage? Or am I missing something here? import { HttpCli ...

A selection dropdown within a grid layout

Hey there, I am currently working on implementing a dropdown list within a data grid. I want to ensure that if I select a value in one row of the dropdown and then select the same value in another row, a message will be displayed saying 'already added ...

Can someone assist me with navigating through my SQL database?

Struggling with a script that searches multiple fields in the same table, I need it to return results even if one or three parameters are left blank. My attempts using PHP and MySql have been fruitless so far, which is why I am reaching out to the experts ...

Guidance on creating cookies using Angular

I have been attempting to set a cookie using the method outlined in this post. However, despite following the instructions, I seem to be missing a crucial step as the console only displays "undefined". Below is the complete HTML content that I am using: & ...

Creating a rotating wheel using JavaScript that is activated by a key press event

I need some help with implementing a keystroke event in this code so that the spinning wheel can start based on a key press, like the spacebar. Any suggestions on how to achieve this? I have found an event code for keystrokes in JavaScript: document.body. ...

Tips for deactivating a single edit button

Is there a way to make it so that when I click on a checkbox, only that specific todo's edit button is disabled? Currently, clicking on a checkbox disables all edit buttons in the todo list. Any suggestions? class App extends Component { state ...