Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
How to scrape all thread links from a XenForo forum board? [closed]
Closed as not constructive by Karl Knechtel on Feb 28, 2026 at 23:56
This question cannot be answered in a way that is helpful to anyone. It's not possible to learn something from possible answers, except for the solution for the specific problem of the asker.
This question was closed; new answers can no longer be added. Users with the Vote on Holds ability may vote to reopen this question if it has been improved or closed incorrectly.
I'm trying to extract all thread links from a specific board on a XenForo forum (similar to this one: Creative Writing, specifically this one: NSFW Creative Writing), but a simple script I tried stops working on the second page.
I'm using a JavaScript snippet that runs directly in the browser's console because I want to use my existing logged-in session. I would normally use Python but I don't know how to handle the login authentication from Python.
The script automatically clicks through all the pages of the forum board and collects every unique thread link it finds.
Here is the complete script. Copy, navigate to the first page of the forum board to scrape, open the browser's developer console (usually by pressing F12), paste the script, and press Enter.
(async function() {
const allLinks = new Set();
let currentPage = 1;
let hasNextPage = true;
while (hasNextPage) {
console.log(`Scraping page ${currentPage}...`);
// Get all thread links on current page
const links = document.querySelectorAll('a[href*="/threads/"]');
links.forEach(link => {
if (link.href && !link.href.includes('#') && link.href.includes('/threads/')) {
allLinks.add(link.href);
}
});
// Check for next page button - XenForo usually uses rel="next"
const nextButton = document.querySelector('a.pageNav-jump--next, a[rel="next"]');
if (nextButton) {
nextButton.click();
// Wait for the next page to load
await new Promise(resolve => setTimeout(resolve, 5000));
currentPage++;
} else {
hasNextPage = false;
}
}
// Display and copy results
console.log(`Finished! Found ${allLinks.size} unique thread links.`);
const linksArray = Array.from(allLinks);
const linksText = linksArray.join('\n');
// Copy to clipboard
try {
await navigator.clipboard.writeText(linksText);
console.log('✅ All links have been copied to your clipboard!');
} catch (err) {
console.error('❌ Failed to copy links to clipboard:', err);
// Fallback: log the links to the console
console.log('Links found:', linksArray);
}
return linksArray;
})();
Why does the script fail on the second page, and how can I fix this script to reliably scrape all pages and get all the story links?

2 comment threads