What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
To scrape an HTML table with Cheerio, fetch or supply the page’s markup, select the table, traverse its rows and cells, and map those values to meaningful headings. Cheerio parses HTML but does not run the page’s JavaScript, so a table created only after browser rendering will not be present in the source markup.
Install Cheerio and choose your Node.js version
Install the package in your project with:
npm install cheerio
The Cheerio documentation viewed for this article lists Node.js 22.19 or later as the current requirement. Check the official introduction for the requirement that applies to the version you install, since package requirements can change.
For an ES module, import Cheerio like this:
import * as cheerio from 'cheerio';
In a CommonJS project, use:
const cheerio = require('cheerio');
Cheerio is a server-side HTML parser, not a web browser. It does not execute scripts, apply browser layout, or render the page. If a table is already present in the HTML response, it is a good fit; if a script inserts the table after loading, you need to obtain the rendered data another way.
Fetch the page or load markup you already have
If you have an HTML string, pass it to cheerio.load. If you are retrieving a public page, check the HTTP response before parsing it so that an error page or unexpected response is not mistaken for the table.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
import * as cheerio from 'cheerio';
const url = 'https://example.com/data';
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Request failed: ${response.status} ${response.statusText}`);
}
const contentType = response.headers.get('content-type') ?? '';
if (!contentType.includes('text/html')) {
throw new Error(`Expected HTML, got: ${contentType || 'no content type'}`);
}
const html = await response.text();
const $ = cheerio.load(html);
Replace the example URL with a page you are permitted to access. Respect the site’s terms, access controls, and applicable law; a successful HTTP response does not grant permission to reuse the content.
Choose the loader for the input you have
cheerio.load(html)is the basic choice for an HTML string.loadBufferaccepts raw bytes when you have not already decoded the response.decodeStreamandstringStreamsupport stream-based input.fromURLcan fetch and parse a URL directly. The loading guide says it follows up to five redirects, rejects non-2xx responses and non-markup content types, selects XML mode according to the response content type, and sets the final URL as the base URI.
See the Cheerio loading guide for the current loader APIs and details. For a first scraping script, explicit fetch plus load makes response handling easy to see; use fromURL when its built-in behavior matches your needs.
Select the right table, not just the first one
A page may contain several tables: navigation, pricing, related content, or data you do not want. Prefer a stable identifier, class, caption, or distinctive containing region over $('table').first(). Cheerio supports CSS-style selectors and traversal; the exact selector must match the page’s actual markup.
// Prefer a stable id or class when the page provides one:
const table = $('table#results');
// Other possible starting points, depending on the HTML:
const byClass = $('table.data-table');
const byCaption = $('table').filter((_, el) =>
$(el).find('caption').text().trim() === 'Quarterly results'
);
The caption example illustrates a selection pattern, not a guarantee about any particular site. Inspect the downloaded HTML and adapt the selector to its structure. If the table is inside a specific section, select that region first and search within it. Keep subsequent queries scoped to the chosen table to avoid accidentally collecting cells from other tables.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsCheerio’s selection guide and traversal guide cover supported selection and traversal patterns.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Extract rows and cells into arrays
For a regular table, collect each row’s header and data cells with find('th, td'). Normalize whitespace if line breaks and indentation in the markup are irrelevant to your data.
const table = $('table#results');
if (!table.length) {
throw new Error('Results table was not found');
}
const rows = table.find('tr').toArray().map((row) =>
$(row)
.find('th, td')
.toArray()
.map((cell) => $(cell).text().trim().replace(/s+/g, ' ')),
);
console.log(rows);
This returns an array of arrays. A row such as <tr><th>Name</th><td>Ada</td></tr> becomes ['Name', 'Ada']. Using .text() returns text from nested markup too, so a link or emphasis inside a cell does not prevent text extraction.
Check for missing or unexpected rows before using the result:
Recommended Free Tools
if (rows.length === 0) {
throw new Error('The selected table has no rows');
}
console.log(`Found ${rows.length} table rows`);
For real pages, decide whether to retain header rows, footer rows, empty cells, or nested table content. A nested table can cause a parent row’s find('th, td') to include cells from inside the nested table; if that matters, select only the intended direct children or otherwise handle nested tables separately.
Map headings to records for a simple table
If the table has exactly one header row and each data row has the same number of cells, convert the array output to objects. This common pattern assumes a regular table with one straightforward row of column headings.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
const [headers, ...dataRows] = rows;
if (!headers || headers.length === 0) {
throw new Error('No header row found');
}
const records = dataRows.map((row, index) => {
if (row.length !== headers.length) {
throw new Error(
`Row ${index + 2} has ${row.length} cells; expected ${headers.length}`
);
}
return Object.fromEntries(headers.map((header, column) => [
header,
row[column],
]));
});
console.log(records);
A row with values ['Ada', 'Engineer'] and headings ['Name', 'Role'] becomes { Name: 'Ada', Role: 'Engineer' }. Validate row lengths rather than silently pairing mismatched cells; otherwise a missing cell can shift or omit data without an obvious error.
Do not assume the first row is the column header
HTML tables can use <th> for row headings as well as column headings, contain multiple header rows, or associate cells using scope, id, and headers. Examine the table’s markup and semantics before treating its first row as keys. The HTML table model describes table structure; Cheerio’s extract documentation also shows declarative extraction patterns for repeated and nested data.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteFor multi-level headings, you may need to build compound keys such as 2025 Revenue from more than one header row, or use explicit rules based on the table’s header relationships. There is no universal mapping that can infer the intended meaning of every irregular table.
Account for rowspan and colspan
A simple row-and-cell loop returns the source cells; it does not expand spanning cells into a rectangular grid. A cell with rowspan="2" occupies a logical position in two rows, while colspan="3" occupies three columns. If your output needs one value in every grid position, you must implement span expansion or use a table-specific mapping strategy.
Before normalizing spans, inspect both attributes and decide how a repeated value should be represented in your output. A practical grid-expansion algorithm tracks occupied column positions across rows: when it encounters a cell, find the next unoccupied column, place its value across its colspan, and reserve those positions for the number of rows in its rowspan. Each following source cell goes into the next available column. This also requires handling invalid or absent span values and deciding whether to duplicate the spanning text or retain a reference to its source cell.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
If a regular array of source cells is enough for your use case, do not expand spans. If column alignment matters, test the expansion logic against the actual table, including its header rows and any nested tables. The HTML standard defines these span attributes and the table grid; they are not merely decorative metadata.
When Cheerio cannot see the table
Cheerio only parses the markup you give it. If the initial response contains a placeholder and client-side code fetches the table later, cheerio.load will not execute that code or wait for the data. Confirm this by inspecting the raw response or searching it for an expected table value.
- Look for a public data source: the page may load JSON or another endpoint that provides the table’s data directly. Use it only if it is accessible and permitted for your purpose.
- Use a rendering-capable browser tool: Puppeteer or Playwright can load a page with JavaScript and expose the resulting DOM. That adds browser setup and resource costs compared with parsing static HTML.
- Use a screenshot when the visual result is what you need: a screenshot is an image or PDF, not structured table data, so it is not a substitute for extracting cell values.
Handle common failures
| Symptom | Likely cause | What to do |
|---|---|---|
| “Table was not found” | The selector does not match, the response differs from the browser view, or the table is added by JavaScript. | Inspect the response HTML, verify the selector against it, and check whether the table exists only after rendering. |
| Fetch returns an error status | The server returned a non-success response, such as a missing page or access denial. | Check the URL and response status. Do not treat an error document as the expected table. |
| Parser receives non-HTML content | The URL returned JSON, an image, or another content type. | Inspect the response content type and use the appropriate data parser or endpoint rather than parsing it as HTML. |
| Rows have different lengths | There are missing cells, spanning cells, multiple header rows, or nested table cells. | Inspect the affected rows and model the table’s structure instead of zipping every row blindly. |
| Text includes unexpected line breaks or spacing | Whitespace and nested elements in the source affect extracted text. | Normalize whitespace where appropriate, but preserve meaningful separators and values. |
| Some rows or values are absent | The data may be paginated, hidden until interaction, loaded dynamically, or outside the selected table. | Inspect pagination and page behavior; determine whether each page or a permitted data source must be handled separately. |
Cheerio’s fromURL rejects non-2xx responses and non-markup content types rather than treating them as ordinary HTML. With a separate fetch call, make those checks yourself, as in the earlier example. The loader’s redirect and content-type behavior is documented in the loading guide.
Keep scraped markup and values safe
Parsing is not sanitizing. Cheerio’s security guidance notes that scripts and event-handler attributes can remain in parsed and serialized markup. Extracting a cell’s text is different from treating its HTML as trusted content.
- Do not render scraped HTML in a trusted page without appropriate sanitization.
- Prefer text extraction when you need table values rather than markup.
- Do not interpolate untrusted input into a selector. Select stable elements, then compare untrusted values as data.
Read Cheerio’s security guide before storing or displaying scraped HTML.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Or skip the browser setup
If you need a visual capture rather than structured cell data, ScreenshotNeo is a website screenshot API and MCP server. One GET request can return a PNG, JPEG, WebP, or PDF; see the API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/data -o shot.webp
ScreenshotNeo accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status in headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.
The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Every feature is on every plan. A screenshot is a visual record, not an array of table values, so use Cheerio or a browser-rendered DOM when your output needs structured data. Sign up for ScreenshotNeo’s free plan.
Frequently Asked Questions
Can Cheerio scrape a table that appears after I open a page in a browser?
Only if the table is already in the HTML you provide. Cheerio does not execute client-side JavaScript; obtain the data separately or use a browser-rendering tool.
Does Cheerio automatically expand merged table cells?
No. A basic row-and-cell traversal returns the source cells and leaves rowspan and colspan normalization to your code.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

