[{"data":1,"prerenderedAt":20},["ShallowReactive",2],{"blog-post-en-extract-paginated-web-tables-to-csv-broma":3},{"slug":4,"lang":5,"title":6,"summary":7,"date":8,"tags":9,"tag_slugs":15,"thumbnail_url":16,"translations":17,"body":18,"asset_base":19},"extract-paginated-web-tables-to-csv-broma","en","Extract Paginated Web Tables to CSV in Broma","A step-by-step Broma workflow for reading a paginated web table, handling the Next button, and exporting clean CSV without fixed sleeps or brittle selectors.","2026-11-13",[10,11,12,13,14],"browser-automation","csv-export","web-tables","no-code","pagination",[10,11,12,13,14],"https:\u002F\u002Fblog-api.bromaapp.com\u002Fapi\u002Fblog\u002Fposts\u002Fextract-paginated-web-tables-to-csv-broma\u002Fthumbnail.svg?lang=en",[5],"Paginated tables are one of the most common browser chores: a supplier catalog, a stock list, a public directory, a dashboard report. The task looks simple until page two. Rows duplicate, the Next button disappears, a column shifts because a product name contains a comma, or the flow clicks Next before the table has refreshed.\n\nThis guide builds one focused Broma workflow: read a public paginated table, collect rows across pages, and export a clean CSV. It assumes the table is ordinary HTML and the site allows this kind of collection at a polite pace. Check the site terms first, keep the volume reasonable, and do not collect personal data.\n\n## Start with the output contract\n\nBefore touching selectors, decide what one row means. For a supplier catalog, the contract might be:\n\n- One row per product variant\n- Columns: SKU, Product, Price, Stock\n- Header row included once\n- CSV fields quoted so commas and line breaks do not shift columns\n\nWrite that contract down. It prevents the common failure where the workflow collects visible text but not the fields you actually need.\n\n## Pick selectors that describe the table, not its position\n\nOpen the page in Broma, use the browser inspector, and look for stable attributes. Good anchors are usually:\n\n```text\n#catalog\n#catalog tbody tr\ntd[data-field='sku']\nbutton[aria-label='Next page']\n[data-testid='page-number']\n```\n\nAvoid selectors like `body > div:nth-child(4) > table`. They break when a banner, cookie notice, or layout wrapper appears. If the table has no stable IDs, anchor to the nearest stable container and document the column order in the flow. A selector that is slightly less elegant but easy to repair is better than a clever selector nobody can maintain.\n\nFor the Next button, prefer a selector that also exposes state:\n\n```text\nbutton[aria-label='Next page']:not([disabled])\n```\n\nIf the site hides the button on the last page, the wait step will fail cleanly instead of clicking a dead control.\n\n## Read one page into rows\n\nAdd an Evaluate expression step after the page has loaded. This expression returns an array of arrays, one inner array per table row:\n\n```javascript\n(() => {\n  const table = document.querySelector('#catalog');\n  if (!table) return [];\n  return [...table.querySelectorAll('tbody tr')]\n    .filter(tr => tr.querySelectorAll('td').length > 1)\n    .map(tr => [...tr.querySelectorAll('td')].map(td => td.textContent.trim()));\n})()\n```\n\nWhy read the whole row at once? It keeps the row cells aligned. If you read each column with a separate step, a missing cell on one row can silently shift every later value. The filter removes spacer or message rows that are not real records.\n\nIf the table uses links, `textContent` still gives you the visible label. If you need the URL, read the `href` attribute in a separate expression and append it as another column.\n\n## Convert rows to CSV safely\n\nDo not join cells with commas directly. Product names often contain commas, quotes, or line breaks. Use a small expression that quotes every field and doubles internal quotes:\n\n```javascript\nconst q = String.fromCharCode(34);\nconst nl = String.fromCharCode(10);\nconst esc = v => {\n  const s = String(v).trim();\n  return q + s.split(q).join(q + q) + q;\n};\nreturn rows.map(r => r.map(esc).join(',')).join(nl);\n```\n\nIn the flow, keep a text variable called `csv`. Initialize it with the header once:\n\n```text\nSKU,Product,Price,Stock\n```\n\nAfter each page, append a newline and the converted rows. Quoting every data field is acceptable and makes the file predictable. If you need a page number for debugging, add it as a fifth column before conversion.\n\n## Loop through pages without fixed sleeps\n\nA fixed wait is the main reason these flows fail. Page two may load in 300 ms or three seconds. Instead of sleeping, wait for evidence that the table changed.\n\nUse this loop shape:\n\n1. Set `page = 1`, `csv = header`, and `previousFirstRow = ''`.\n2. Read the current table rows and append them to `csv`.\n3. Save the first row text as `previousFirstRow`.\n4. Check whether the Next button exists and is enabled. If not, stop.\n5. Click Next.\n6. Wait until the first row is different from `previousFirstRow`, or until the page indicator changes.\n7. Increment `page` and repeat, with a maximum page guard such as 50.\n\nThe wait condition can be a short expression:\n\n```javascript\n(() => {\n  const first = document.querySelector('#catalog tbody tr td');\n  if (!first) return false;\n  return first.textContent.trim() !== previousFirstRow;\n})()\n```\n\nIn Broma, compare against the saved variable in the Wait for condition step. If the site exposes a page number, use that instead; it is usually more reliable than row text. Add a one- to two-second pause between pages only if the site expects a polite pace. That pause is not a substitute for the change check.\n\n## Export and verify the CSV\n\nSave the `csv` variable to a file with a Save file step. Then verify three things before trusting the run:\n\n- The first data row matches the first row you see manually.\n- The last row belongs to the last page, not the second-to-last.\n- The row count is close to `pages x rows per page`, allowing for the final partial page.\n\nIf the count is too high, you probably appended the same page twice. If it is too low, the loop stopped early or the table selector missed rows during a re-render.\n\n## Troubleshooting the common failures\n\n### Duplicate rows\n\nThe click happened before the table refreshed. Wait for the page indicator or first-row change, not for the click itself.\n\n### Missing final page\n\nSome sites disable Next by removing the element, others by adding `disabled`. Check both states. Also confirm that the final page is not loaded by a separate Show more control.\n\n### CSV columns shifted\n\nA field contains a comma or newline. Use the quoting expression above and open the file in a spreadsheet to inspect the first few rows.\n\n### Selector worked once, then failed\n\nThe table re-rendered and replaced the node. Anchor to the stable table container and wait for rows to exist before reading them.\n\n### Infinite scroll instead of pagination\n\nThis recipe is for explicit pagination. Infinite scroll needs a different pattern: scroll, wait for the row count to increase, and stop when the count stops changing. Do not mix the two approaches.\n\n## Where AI helps, and where it does not\n\nYou can describe the table and pagination to Broma's AI agent and ask for a selector map and loop plan. Treat that as a draft. Open the page, verify each selector in the inspector, and test the wait condition manually. AI is optional and runs on your own AI account; it is not included in the Broma price.\n\nOnce the flow works, keep the selectors in one small variable block at the top. When the site changes, one edit fixes the whole workflow. That is the difference between a one-off extraction and a reusable operations tool.\n","https:\u002F\u002Fblog-api.bromaapp.com\u002Fapi\u002Fblog\u002Fposts\u002Fextract-paginated-web-tables-to-csv-broma\u002Fassets",1794729620614]