Web scraping
How do I scrape click-to-reveal or expandable content?
First check whether the hidden text is already in the page source; it often is. If it is loaded on click, call the same request the button sends, or click the button in a browser and read the result.
The answer in three cases
"Read more" links, accordions, tabs and "show phone number" buttons look alike on screen but work in three different ways underneath. The content is either already in the HTML and hidden with CSS, fetched from the server when you click, or built by a script from data already loaded on the page. Find out which one you have before writing code, because the simplest case needs no clicking at all.
Case one: hidden but present
Open the page source (not the Elements panel) and search for a phrase from the hidden text. If you find it, the content is in the document and only styled as hidden, through display:none, a collapsed <details> element, an aria-hidden panel or a tab that is not active. Any HTML parser reads it like visible text:
import bs4
page = bs4.BeautifulSoup(source_html, "html.parser")
answers = {}
for block in page.select("details.faq-entry"):
question = block.select_one("summary").get_text(" ", strip=True)
body = block.select_one(".answer").get_text(" ", strip=True)
answers[question] = body
Parsers do not care about CSS visibility. Browser automation does: Selenium's element.text returns an empty string for invisible elements, while get_attribute("textContent") returns the text regardless.
Case two: loaded on click
If the text is not in the source, open DevTools, switch to the Network tab, filter by Fetch/XHR and click the button. A new request appears, usually returning JSON or a small HTML fragment. That request is your real target. Copy its URL, method, headers and body, then call it directly with your HTTP client. This is often the cleanest form of hidden API scraping: one small request per item instead of a full page render.
Watch for parameters the request depends on: an item id taken from the page, a CSRF token from a meta tag, or a session cookie. Reveal buttons for contact details are often rate limited or placed behind a CAPTCHA, because they protect personal data. Treat that as a signal: collect contact details only where you have a lawful basis and the site permits it.
Case three: needs a browser
When the request is signed by a script, or the content is computed in the page, click it for real. In Playwright:
for (const toggle of await page.locator("button.expand-review").all()) {
await toggle.click();
}
await page.waitForFunction(() => document.querySelector(".review-body.open") !== null);
const reviews = await page.locator(".review-body.open").allTextContents();
Click every toggle, wait for a sign that the content has arrived, then read everything at once. Waiting on a fixed delay instead tends to be either too short on slow pages or wasteful on fast ones.
Useful tricks
- Expand all at once. Many accordions honor an "expand all" control or a URL parameter. Use it when present.
- Open details elements with a script.
document.querySelectorAll("details").forEach(d => d.open = true)opens native disclosures in one call. - Intercept the response. In Playwright or Puppeteer, listen for the response of the reveal request and read its JSON, instead of parsing the rendered text.
- Scroll first. Some toggles only exist after lazy loading. Bring them into view before clicking, as described on scrolling to an element.
When a click leads to a CAPTCHA
Sites sometimes show a reCAPTCHA or Turnstile widget after a few reveals. The page then expects a token with the next request. Read the site key from the widget, create a task through the GateSolver API, and send the returned token in the field or parameter the reveal request uses. Slow down as well: if the widget appears after a fixed number of clicks, pacing your requests usually reduces how often you see it.
Common mistakes
Clicking in a browser when the text was in the HTML all along is the most frequent one, and it makes scrapers ten times slower than needed. The second is reading .text in Selenium from collapsed panels and getting empty strings. The third is replaying a reveal request without the cookie or token it needs and concluding the endpoint is broken. Compare your request with the one in DevTools header by header before giving up.
Common questions
Why does Selenium return empty text for hidden elements?
Its .text property returns only visible text. Read the textContent attribute to get text from hidden elements.
How do I know if content loads on click?
Search the raw page source for a phrase from it. If it is missing, watch the Network tab while clicking.
Can I call the reveal endpoint without a browser?
Often yes, as long as you send the same parameters, cookies and tokens the page sends.
Is scraping revealed phone numbers allowed?
It depends on the site terms and data protection law. Personal data needs a lawful basis, so check before collecting it.
What if each reveal needs a CAPTCHA token?
Solve the widget for that request with a token task and include the token, and space out your reveals.
Keep reading
- Hidden API scrapingReading the JSON endpoints a page quietly calls, so you collect clean data without parsing the rendered HTML.
- Dynamic scrapingDynamic scraping collects data loaded by scripts or background XHR calls, either by driving a browser or calling those endpoints directly.
- How do I tell if a page is static or dynamic?Compare the raw HTML with what the browser shows: if your data is missing from the source, JavaScript adds it.
- JavaScript renderingJavaScript rendering runs page scripts so browser built content appears; you need it only when the data lives nowhere else.