Gaming | Xbox Profile Games Scraper
Pricing
Pay per usage
Gaming | Xbox Profile Games Scraper
Given an xbox username it will scrape all the game data
Pricing
Pay per usage
Rating
0.0
(0)
Developer

Eshaam Rabaney
Actor stats
0
Bookmarked
1
Total users
0
Monthly active users
3 days ago
Last modified
Categories
Share
๐ฎ XBOX Gamertag Scraper (Apify Actor)
This project is an open-source Apify Actor designed to scrape public game history and statistics for any given Xbox Gamertag from the xboxgamertag.com website. It uses the PlaywrightCrawler to handle dynamic content loading and bypass common bot detection mechanisms that caused the original 503 errors.
๐ Features
- Playwright Integration: Uses a real, headless browser to ensure robust scraping of dynamic, JavaScript-rendered content.
- Gamerscore Extraction: Retrieves the user's Total Gamerscore.
- Game Detail Scraping: Collects data for each played game, including:
- Game Title
- Gamerscore Earned / Total Possible
- Completion Progress (%)
- Last Played Date
- Platform
- Cover Image Link
๐ ๏ธ Setup and Installation
Prerequisites
- Node.js: Installed on your system (v18 or higher recommended).
- Apify Account: Needed to run the actor on the Apify platform (optional for local development).
- Apify CLI:
$npm install -g apify-cli
Local Development
- Clone the Repository:
git clone [https://github.com/your-username/gaming-xbox-scraper.git](https://github.com/your-username/gaming-xbox-scraper.git)cd gaming-xbox-scraper
- Install Dependencies:
$npm install
- Create Input File:
Create a file named
INPUT.jsonin the root directory with the following structure:{"username": "deadpaul4"// Replace "deadpaul4" with the Gamertag you want to scrape} - Run Locally:
The results will be stored in the local$apify runapify_storage/key_value_stores/defaultdirectory.
๐ป Code Details (src/main.js)
The core logic is structured to ensure reliability and proper execution within the Apify environment.
Key Technical Details
-
Async IIFE (Top-Level Execution Wrapper): The entire script is wrapped in an
(async () => { ... })();to ensureawait Actor.init()is executed successfully before any other Apify SDK methods are called, preventing runtime initialization errors. -
PlaywrightCrawler: Used instead of CheerioCrawler to overcome the 503 Internal Server Error by simulating a real browser visit, which is necessary for websites using bot detection.
-
page.evaluate(): The complex data extraction logic is executed entirely within apage.evaluate()block. This code runs in the browser's context, allowing the use of standard DOM manipulation (e.g.,document.querySelectorAll) after the page's JavaScript has executed. -
Local Logging (Console): For local runs, the main execution block uses
console.logfor immediate output, while therequestHandlerstill uses the dedicatedlogobject provided by Crawlee for structured logging.
import { Actor } from 'apify';import { PlaywrightCrawler } from 'crawlee';// Wrap the entire execution in an Asynchronously Invoked Function Expression (IIFE)(async () => {// --- INITIALIZATION ---await Actor.init();// --- VARIABLE DECLARATIONS ---let USERNAME = 'TEST_GAMERTAG';let totalGamerscore = 0;// --- CRAWLER DEFINITION ---const crawler = new PlaywrightCrawler({requestHandlerTimeoutSecs: 60,async requestHandler({ page, request, log }) {log.info(`Processing game history page for user: ${USERNAME}`);try {// Wait for the dynamic content to be loadedawait page.waitForSelector('.game-card', { timeout: 15000 });} catch (error) {log.warning('Timed out waiting for game cards. The user profile may be empty or failed to load.');}// --- Scraping Logic using page.evaluate() ---const results = await page.evaluate((USERNAME) => {// 1. Gamerscore Extraction (omitted for brevity)// ...const totalGamerscore = 0; // Placeholder// 2. Extract Game Cards (omitted for brevity)const games = []; // Placeholderreturn { games, totalGamerscore };}, USERNAME);// --- Post-Evaluation ---totalGamerscore = results.totalGamerscore;if (results.games.length > 0) {await Actor.pushData(results.games);log.info(`โ Successfully extracted and pushed ${results.games.length} game records.`);} else {log.warning('โ ๏ธ No game records were found after evaluating the page.');}},});// ------------------------------------------------------------------// --- EXECUTION BLOCK ---const { npsso, username } = await Actor.getInput() || {};if (username) {USERNAME = username;console.log(`INFO: Starting Playwright crawler for user: ${USERNAME}`);if (npsso) {console.log("INFO: NPSSO token found in input. (Not used in this public scraper, but available).");}await crawler.run([`https://xboxgamertag.com/search/${username}`]);} else {console.log("ERROR: Missing username in INPUT.json. Crawler aborted.");}await Actor.exit();})(); // End of IIFE