To scrape a paginated table in your web browser, where you have a "Next" button to switch pages, you can use JavaScript in the browser console to automate the process. Here’s a step-by-step guide:
1. Open the Webpage
Navigate to the page with the table in your browser (e.g., Chrome).
2. Open Developer Tools
- Press
F12 or Ctrl+Shift+I (Windows/Linux) or Cmd+Option+I (Mac).
- Go to the Console tab.
3. Identify the Elements
- Table:
class="table_table__8D7gp"
- Next Button: The long class string you provided (we'll use a selector for this).
4. Paste and Run the Script
Here’s a script you can paste into the console. It will:
- Extract the table HTML on each page.
- Click the "Next" button.
- Save each table as a file.
- Stop when the "Next" button is disabled or not found.
(async function scrapePaginatedTable() {
let page = 1;
while (true) {
// 1. Get the table HTML
let table = document.querySelector('.table_table__8D7gp');
if (!table) {
console.log('Table not found!');
break;
}
let tableHtml = table.outerHTML;
// 2. Save the table HTML as a file
let blob = new Blob([tableHtml], {type: 'text/html'});
let a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `table_page_${page}.html`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
// 3. Find the "Next" button
let nextBtn = document.querySelector('.MuiButtonBase-root.MuiButton-root.MuiButton-contained.MuiButton-containedSecondary.MuiButton-sizeSmall.MuiButton-containedSizeSmall.MuiButton-colorSecondary.MuiButtonGroup-grouped.MuiButtonGroup-groupedHorizontal.MuiButtonGroup-groupedContained.MuiButtonGroup-groupedContainedHorizontal.MuiButtonGroup-groupedContainedSecondary.MuiButton-root.MuiButton-contained.MuiButton-containedSecondary.MuiButton-sizeSmall.MuiButton-containedSizeSmall.MuiButton-colorSecondary.MuiButtonGroup-middleButton.css-cbvs2h');
// 4. Check if the button is disabled or not found
if (!nextBtn || nextBtn.disabled) {
console.log('No more pages or next button disabled.');
break;
}
// 5. Click the "Next" button
nextBtn.click();
// 6. Wait for the table to update (adjust timeout as needed)
await new Promise(resolve => setTimeout(resolve, 1500));
page++;
}
console.log('Scraping complete!');
})();
5. How it Works
- Saves each table page as
table_page_1.html, table_page_2.html, etc.
- Clicks the "Next" button to go to the next page.
- Waits 1.5 seconds for the table to update (adjust if your table loads slower/faster).
- Stops when the "Next" button is disabled or not found.
6. Tips
- If the table loads via AJAX and takes longer, increase the timeout in
setTimeout.
- If the button class changes, use browser dev tools to get the correct selector.
- For more advanced scraping (e.g., extracting data as CSV), the script can be modified.
7. Alternative: Use a Browser Extension
If you want a GUI, try extensions like "Web Scraper" or "Data Miner" for Chrome, which can handle pagination.
Let me know if you want the script to extract table data as CSV or JSON instead of HTML!