Extract text from website API: 3 methods compared
Need to extract text from website API calls? Send one POST with the page URL and read the rendered output. Compare three routes, then run the curl example.
- web scraping
- text extraction
- web data api
- playwright
- cdp
On this page
- What counts as text when you extract text from a website?
- Why does a plain HTTP fetch return different text than a browser?
- Parser, hosted browser or extract text from website API: which should you use?
- How do you call an extract text from website API?
- What each failure means
- How do you extract text from logged-in or multi-step pages?
- Agents and RAG
- How do you extract text from sites that block bots, and is it allowed?
- What does an extract text from website API cost per page?
- Frequently asked questions
- How do you extract text from a website with an API?
- What is the difference between textContent and innerText?
- Why does my scraper return empty text from a JavaScript page?
- Is it allowed to extract text from a website?
- How do you start extracting text from websites this week?
- Sources
The most direct extract text from website API pattern is to send the URL to an endpoint that renders the page in a real browser and returns markdown or JSON: with Wayfern’s Web Data API, call POST https://api.wayfern.com/api/v1/scrape. A plain fetch plus an HTML parser suffices for static, unblocked pages, and a CDP-driven browser handles logins and multi-step flows. Each response returns credits charged; failed work isn’t billed.
Your script fetches a URL, parses the HTML and prints an empty body, a cookie banner or a 403. The same page shows a full article in your browser.
After reading, you can choose between a parser, a hosted browser and an extract text from website API. You can also run a working request in curl and Python, handle each failure class and estimate the cost per page.
Key Takeaways
- Decide which text you need before you pick a tool: visible text, every DOM string and the article body differ.
- A 200 response can carry an empty or consent body, so check text length or an expected element.
- Use a stateless API call for many single pages and a CDP browser session for logins and forms.
- Treat a blocked page as an expected result: a residential retry improves the odds but guarantees nothing.
What counts as text when you extract text from a website?
Text from a web page means one of three things: what a visitor sees, every string in the DOM (navigation and cookie banners included), or the main article body. Each comes from a different method, so pick the one that matches what you do with the output next.

MDN’s textContent reference says textContent gets the content of all elements, including script and style elements. The output carries noise but misses nothing, which suits search indexing or diffing a page against its previous version.
MDN defines innerText as the rendered text content of a node and its descendants. Anything hidden by CSS is absent, so it fits monitoring what a visitor actually sees.
Mozilla describes its Readability library as the one used for Firefox Reader View. It returns the article and little else, which fits LLM or RAG ingestion.
Reader View targets article-like pages. A product grid, a dashboard or a listing page has no single article body to pick, so test Readability on those pages before you rely on it.
A worked example: say a page holds a navigation bar, a div with display:none wrapping a cookie-consent paragraph, and an article.
textContentreturns the navigation, the consent paragraph and the article.innerTextreturns the navigation and the article, because the hiddendivisn’t rendered.- A Readability pass returns the article only.
Playwright exposes the first two on a locator. According to Playwright’s Locator docs, locator.textContent() returns the node’s textContent and locator.innerText() returns the element’s innerText.
Why does a plain HTTP fetch return different text than a browser?
A plain HTTP fetch returns the server’s first response, while a browser runs that response’s JavaScript and shows the text of the final DOM. The browser parses the HTML, executes scripts, calls other endpoints and rewrites the page. A fetch stops before any of that happens.
When the server puts the article text in the HTML, a fetch plus a parser is enough. It fails in four cases:
- An app shell: the body holds an empty root container until scripts fill it.
- A late XHR: the text arrives from a separate request after the page loads.
- A lazy-loaded section: content below the fold isn’t requested until the page scrolls.
- An interstitial or consent page: the server returns it in place of the article.
Hosted text APIs let you switch rendering on per request. Some APIs, such as URLtoText, expose rendering as render_javascript.
When you drive the browser yourself, Playwright’s page.goto takes a waitUntil option. Its docs describe load and domcontentloaded as finished when those events fire, commit as finished when “network response is received and the document started loading”, and networkidle as “DISCOURAGED”.
None of these states means your text is on screen, so wait for a specific element:
await page.goto(url, { waitUntil: "domcontentloaded" });
await page.waitForSelector("article h1");
const text = await page.innerText("article"); A fetch-based extractor also sees status codes. RFC 9110 says 403 means the server “understood the request but refuses to fulfill it” and 503 means it is “currently unable to handle the request”. RFC 6585 defines 429 as the user having “sent too many requests in a given amount of time”.
A 200 response with an empty or consent body raises no error. That trap catches every extract text from website API client too. Check the text length or look for your expected element before you accept the result.
Parser, hosted browser or extract text from website API: which should you use?
Use a fetch and parser for static public pages, a Web Data API call for rendered text from many URLs, and a hosted browser for logins and multi-step flows.
| Criterion | Fetch + parser | Hosted browser over CDP | Web Data API call |
|---|---|---|---|
| Handles | Server-rendered HTML | Logins, forms, clicks, multi-step flows | Rendered text from one URL per call |
| You maintain | Parser, retries, proxies | Playwright or Puppeteer scripts | Request code only |
| Fails when | JavaScript builds the text, or the server blocks you | Your flow breaks or a step times out | The task needs state between pages |
| Billing unit | Your own server time | Open-page hour | Page |
Start with the cheapest route that returns the text you need. Not every job needs an extract text from website API.
A plain fetch plus an HTML parser or Readability costs no credits, runs fast and stays under your control. It wins when the page is server-rendered and unblocked and you fetch only a few pages.
The fetch route stops working when JavaScript writes the text after load, or when the server answers a script with an error instead of the article.
An extract text from website API call fits when you need rendered text from many pages and don’t want to run a browser fleet. Each request returns one page and keeps no state afterward, so it can’t carry a login from one call to the next. Wayfern’s Web Data calls bill per page.
A hosted browser covers that gap. You connect with connectOverCDP from Playwright, log in, fill the form and read the page once it settles.
The hosted browser bills by open-page hour, so a flow you leave open keeps costing. Current rates are on the pricing page, and our buyer’s guide to web scraping tools compares more tools by billing unit.
How do you call an extract text from website API?
You extract text with one authenticated POST to https://api.wayfern.com/api/v1/scrape carrying the page URL, and the response holds the page’s rendered output plus the credits that call cost. The full field list is in the scrape reference in /docs/api.
- Create a
wf_token and runexport WF_TOKEN=wf_.... Keep the token out of source files. - Send the curl request below. Set the output format (markdown or JSON) with the field named in the scrape reference.
curl -X POST https://api.wayfern.com/api/v1/scrape \
-H "Authorization: Bearer $WF_TOKEN" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/article", "proxy": "auto"}' - Print the raw JSON on your first call and match its keys to the reference.
- Wrap the call in Python with a timeout and a bounded retry.
import os, time, requests
URL = "https://api.wayfern.com/api/v1/scrape"
HEADERS = {"Authorization": f"Bearer {os.environ['WF_TOKEN']}"}
def scrape(page_url, tries=3):
body = {"url": page_url, "proxy": "auto"} # add the output format field from /docs/api
for attempt in range(tries):
try:
r = requests.post(URL, json=body, headers=HEADERS, timeout=90)
except requests.Timeout:
continue
if r.status_code in (401, 403):
raise SystemExit("Token problem: check scope, expiry, revocation")
if r.status_code == 429:
time.sleep(2 ** attempt * 5)
continue
r.raise_for_status()
payload = r.json()
if not any(payload.values()):
raise ValueError("Empty output")
return payload
raise RuntimeError("Retries exhausted") This extract text from website API client sets a 90-second timeout and stops after three tries, so a stuck page can’t hold a worker forever.
What each failure means
- Auth error: the token is missing, expired, revoked or lacks the right scope. Retrying won’t fix it.
- 429: you exceeded the rate limit. The limits page publishes scrape at 60 requests a minute, with a default of 120 a minute per client IP. Back off and retry.
- Zero credits: calls are refused until you add credits. Auto top-up is off by default, so nothing is charged beyond your balance unless you turn it on.
- Blocked page: a site can refuse even the residential retry that
proxy: "auto"makes, so record the block as a result. - Empty result: a 200 status can still carry no text, so test the output as the Python client does.
When you need typed fields instead of text, the extract endpoint returns JSON from a JSON Schema or a plain-English prompt. The structured data extraction page shows examples. To run the call yourself, get a token from the quickstart.
How do you extract text from logged-in or multi-step pages?
You extract text from a logged-in or multi-step page by driving a real browser session over CDP, signing in, waiting for one selector and reading the rendered text. This example signs in to an account you own and prints one dashboard panel.
import { chromium } from "playwright";
const browser = await chromium.connectOverCDP(
"wss://api.wayfern.com/ws?token=LINK_TOKEN&country=US&session=flow1",
);
const page = await browser.contexts()[0].newPage();
await page.goto("https://example.com/login");
await page.fill("#email", process.env.APP_USER);
await page.fill("#password", process.env.APP_PASS);
await page.click("button[type=submit]");
await page.waitForSelector("#dashboard-panel");
console.log(await page.locator("#dashboard-panel").innerText());
await browser.close(); - Connect and take the first context. Playwright’s
connectOverCDPdocumentation says it attaches to an existing browser over the Chrome DevTools Protocol and exposes the default context throughbrowser.contexts(). - Raise your connect timeout, since a residential exit adds cold-start time.
- Hold one IP for the whole flow. Add the same
sessionid to every connection in a flow, and a residential exit keeps one IP from login to the last page. - Wait for a selector instead of a timer.
waitForSelectorreturns when the element exists, while a fixed sleep returns the login form when the network is slow. - Read with
innerText(), which returns the visible text of that element without hidden nodes.
Cookies and storage live only while the socket is open. The authenticated scraping use case shows the pattern.
Agents and RAG
An agent can run the same extraction through the Wayfern MCP server at https://api.wayfern.com/mcp, with a Bearer wf_ token that has the mcp scope. The scrape_page and extract_data tools bill at REST rates, and each result reports credits_charged.
For RAG ingestion, store the source URL beside every chunk from each extract text from website API call. Then an answer can cite the page it came from.
How do you extract text from sites that block bots, and is it allowed?
You get text from sites that block bots by choosing an exit (the IP address your request leaves from) that the site accepts, and by accepting the refusal when it doesn’t. Whether a collection is permitted is set by the site’s robots.txt, its terms and the law, and an API does not change any of them.
Datacenter exits are cheap and fast, and many sites refuse them first. Residential exits look like ordinary visitors, but they cost bandwidth and add cold-start time. Datacenter egress is free, while residential bandwidth is billed per GB (current rates are on /pricing).
Set proxy to "auto" on the scrape call. Wayfern starts on a datacenter exit and retries on residential when the page blocks it. You can force a datacenter or residential exit and set a country instead, with the field names in the API reference.
If a 403 survives the residential retry, accept the failure. If you get a 429, slow down. On the browser route you can attach your own proxy, and captcha solving is a separate paid call to /api/captcha/solve.
Before you collect from a site, follow these practices:
- Read the site’s
robots.txt. RFC 9309 defines it as a request to crawlers, and it warns that the protocol is “not a substitute for valid content security measures”. Honor it anyway. - Read the site’s terms of service before you collect anything.
- Limit collection to public data, and don’t use a login you don’t own.
- Space out requests and stop when you see 429 responses.
Wayfern’s terms of service also require lawful use.
What does an extract text from website API cost per page?
Extracting text with the Wayfern Web Data API costs 1 credit per page for scrape and extract, and one credit lists at $0.0125 on the pricing page. The output add-on is +4 credits per page and the LLM summary is +2.
The /docs/pricing page says which outputs trigger the output add-on, so check it before you pick a format.
At list rate, 10,000 pages at 1 credit each use 10,000 credits, which is $125. With the LLM summary on every page, each page costs 3 credits, so the same 10,000 pages use 30,000 credits, or $375.
You can buy credits two ways. The Developer plan is $19 a month for 1,520 credits, and credit packs (1,000 for $12.50) never expire and work without a plan. Full tables are on the pricing page.
Billing has a hard stop at zero, so a runaway job can’t produce a surprise bill.
A DIY fetch costs no credits, but you pay in engineering time and your own proxies. The browser route bills differently, at 8 credits per open-page hour, so a multi-step flow isn’t priced per page.
Frequently asked questions
How do you extract text from a website with an API?
Send the page URL in an authenticated POST request, ask for markdown or plain text, and read the text from the response. With Wayfern, that call is POST https://api.wayfern.com/api/v1/scrape, documented in the API reference. Pages that build content with JavaScript need a browser-backed endpoint.
What is the difference between textContent and innerText?
According to MDN, textContent returns the text of every element, including script and style elements. innerText returns only the rendered text a visitor can read. Use innerText for what people see, and textContent when you want every string in the DOM.
Why does my scraper return empty text from a JavaScript page?
A plain fetch returns only the server’s first response, before any script runs. If the text arrives after JavaScript calls other endpoints, it isn’t in that HTML. Read the page from a rendered DOM in a real browser, and wait for one selector that proves the content loaded.
Is it allowed to extract text from a website?
That depends on the site’s rules and what you collect. RFC 9309 defines robots.txt, which lets site owners control how automatic clients access their content. The site’s terms may add limits, so read both and stick to public data.
How do you start extracting text from websites this week?
Today, pick one target URL and decide which text you need: visible text, every string in the DOM, or the main article body. Fetch the page with plain HTTP, run a parser, and check whether that text is in the output.
This week, if the text is missing, make the single POST https://api.wayfern.com/api/v1/scrape call. Read the credits charged in the response, and test a page that returns nothing so your code handles the empty case.
This month, move login and multi-step pages to the CDP route. If you build agents, wire scrape_page over MCP and keep the source URL beside every chunk you index.
To run your first extract text from website API call, create a Wayfern account, mint a token and follow the quickstart in the developer docs, which covers tokens, a CDP connection and a first scrape.
Sources
API Reference - CDP, Web Data & Search | Wayfern · URLtoText - Extract clean text from any website- API… · Node: textContent property - Web APIs | MDN · HTMLElement: innerText property - Web APIs | MDN · RFC 9110: HTTP Semantics · Pricing - Credits for Browsers & the Web Data API | Wayfern · Wayfern MCP docs · RFC 9309: Robots Exclusion Protocol. Every other source is linked where the article cites it.
See us more often in Google
One click marks Wayfern as a preferred source in Google, so our posts can show up more often in your Top Stories, AI Mode and AI Overviews.