<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>61</id><slug>parsing-html-tables-with-beautifulsoup-part-4-61</slug><title>Parsing HTML tables with BeautifulSoup, part 4</title><excerpt>In part 4 we take the ideas from earlier instalments and apply them to a larger, messier site. 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>4</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>In part 4 we take the ideas from earlier instalments and apply them to a larger, messier site. 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>Putting it into practice</heading><paragraphs><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><item>Keep configuration such as base URLs, delays and selectors out of your code. Changing a delay should not require a redeploy.</item></paragraphs></item><item><heading>What to watch for</heading><paragraphs><item>Deduplicate as you go. The same item often appears on several listing pages, and a stable identifier such as a SKU or ID makes duplicates easy to spot.</item><item>Selectors are the most fragile part of any scraper. Prefer stable attributes such as data-testid or semantic structure over generated class names, which can change on every deploy.</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>8</authorId><authorName>Hannah Novak</authorName><authorSlug>hannah-novak</authorSlug><category>Scraping Basics</category><tags><item>javascript</item><item>testing</item><item>scrapy</item></tags><publishedAt>2024-05-12T00:00:00.000Z</publishedAt><wordCount>184</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
