Skip to content
the poor coder

how to scrape data in more button using javascript

Poor Man
Published
Reading time
2 min read
On this page

How to Scrape Data in More Button Using JavaScript#

If you are looking to scrape data from a website that has the "more" button functionality, then you will need to use JavaScript to achieve this. There are several ways to scrape data from "more" buttons using JavaScript, and in this post, I will be discussing a few of these methods.

Method 1: Using XHR Requests#

The first method involves using XHR requests to scrape data from the "more" button. This method involves sending an HTTP request to the server to get the data that is hidden behind the "more" button. Once you have the data, you can parse it and extract the information that you need.

To use this method, you will need to inspect the webpage and find the URL that is called when the "more" button is clicked. You can then use this URL to send an XHR request to the server and get the data that you need.

Text

const xhr = new XMLHttpRequest();
xhr.open('GET', 'url', true);
xhr.onload = function() {
  if (this.status === 200) {
    const data = JSON.parse(this.responseText);
    // Parse and extract data
  }
}
xhr.send();

Method 2: Using a Headless Browser#

The second method involves using a headless browser like Puppeteer to scrape data from the "more" button. This method involves opening the webpage in a headless browser, simulating a click on the "more" button, and then scraping the data that is revealed.

Using a headless browser is more complex than using XHR requests, but it offers more flexibility and allows you to interact with the webpage just like a regular user would.

Text

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('url');
  await page.click('more-button-selector');
  const data = await page.evaluate(() => {
    // Parse and extract data
  });
  console.log(data);
  await browser.close();
})();

Method 3: Using a Web Scraping Library#

The third method involves using a web scraping library like Cheerio or BeautifulSoup to scrape data from the "more" button. This method involves parsing the HTML of the webpage, finding the "more" button, simulating a click, and then scraping the data that is revealed.

Using a web scraping library is the easiest way to scrape data from the "more" button, but it is also the least flexible.

Text

const cheerio = require('cheerio');
const request = require('request');

request('url', function (error, response, html) {
  if (!error && response.statusCode === 200) {
    const $ = cheerio.load(html);
    $('more-button-selector').click();
    const data = $('data-selector').text();
    // Parse and extract data
    console.log(data);
  }
});

These are just a few of the methods that you can use to scrape data from the "more" button using JavaScript. Each method has its own advantages and disadvantages, so choose the method that works best for your needs.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC