<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>21</id><slug>parsing-html-tables-with-beautifulsoup-part-2-21</slug><title>Parsing HTML tables with BeautifulSoup, part 2</title><excerpt>For part 2, we revisit the basics with a fresh example and a few lessons learned the hard way. Tables look like the easiest thing on a page to scrape, until you meet merged cells, header rows that…</excerpt><seriesName>Parsing HTML tables with BeautifulSoup</seriesName><seriesPart>2</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>For part 2, we revisit the basics with a fresh example and a few lessons learned the hard way. Tables look like the easiest thing on a page to scrape, until you meet merged cells, header rows that repeat every twenty lines and numbers formatted for humans rather than machines.</item></paragraphs></item><item><heading>Common pitfalls</heading><paragraphs><item>Pagination comes in several shapes: numbered pages, next links, offsets and opaque cursors. Each has trade-offs, and a robust scraper should detect the end of the result set rather than assuming a fixed number of pages.</item><item>Always identify your client honestly with a descriptive User-Agent, and keep your request rate modest. A crawler that behaves like a considerate visitor is far less likely to cause problems for the site operator.</item></paragraphs></item><item><heading>What to watch for</heading><paragraphs><item>Character encodings still cause trouble. Decode responses using the charset the server declares, and normalise text before comparing or storing it.</item><item>Before writing a single line of code, look at how the page actually loads its data. Open the network panel, reload, and note which requests return the content you care about. Very often the data you want arrives as JSON from an endpoint you can call directly.</item></paragraphs></item><item><heading>Key takeaway</heading><paragraphs><item>Locate the table by a stable attribute, read the header row once, and convert every cell to a typed value before you store it.</item></paragraphs></item></sections><authorId>3</authorId><authorName>Priya Nakamura</authorName><authorSlug>priya-nakamura</authorSlug><category>Scraping Basics</category><tags><item>javascript</item><item>http</item><item>selenium</item></tags><publishedAt>2024-12-02T00:00:00.000Z</publishedAt><wordCount>212</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
