Repository navigation
Conversation
Add first-class support for the Extract API (engine: extract), which
turns any public web page into a structured JSON document and supports
scrape (default), map, and crawl modes.
New methods on SerpApi::Client:
- extract(params): runs an extraction; forces engine=extract and
fails fast when the required :url parameter is missing. All other
parameters (mode, max_pages, max_depth, include_subdomains,
include_sitemap, device, prefetch_delay, timeout, include_tags,
exclude_tags, include_markdown, include_inline_assets, output)
pass through verbatim - the backend remains the source of truth.
- extract_link(link, params = {}): follows a serpapi_extract_link
embedded in Extract results (inline_links, breadcrumbs, price_offers,
urls, pages). It reconstructs the original request parameters from
the link and re-issues it through the client so the api_key, default
params, timeouts, and error handling apply. Guards against non
serpapi.com URLs and non-extract engines, since these links flow out
of scraped web content.
Includes offline unit specs, live example specs, a runnable demo
(demo/demo_extract.rb), and README documentation.
There was a problem hiding this comment.
🟡 Changes recommended
Conflicting engine parameters and link-supplied credential overrides remain unresolved.
2 open findings
What changed in this PR
Adds native Extract API support through the existing client request flow.
Changes:
- Adds
extractandextract_linkhelpers. - Adds unit specifications and live examples for extraction modes.
- Documents usage and updates the class-length limit.
| File | Description |
|---|---|
| spec/serpapi/client/extract_api_spec.rb | Tests helpers and validation. |
| spec/serpapi/client/example/example_extract_spec.rb | Exercises scrape, map, and crawl. |
| README.md | Documents extraction and link following. |
| lib/serpapi/client.rb | Implements Extract API helpers. |
| lib/serpapi.rb | Loads URI parsing support. |
| demo/demo_extract.rb | Demonstrates modes and chained extraction. |
| CHANGELOG.md | Records Extract API support. |
| .rubocop.yml | Raises the class-length limit. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| .transform_keys(&:to_sym) | ||
| raise SerpApiError, "link does not target the extract engine: #{link}" if link_params[:engine] != 'extract' | ||
|
|
||
| search(link_params.merge(params)) |
| raise SerpApiError, "params must be hash, not: #{params.class}" unless params.instance_of?(Hash) | ||
| raise SerpApiError, 'url parameter is required by the extract API' if params[:url].to_s.empty? && params['url'].to_s.empty? | ||
|
|
||
| search(params.merge(engine: 'extract')) |
extract_link merged every parameter from the link, so a link carrying an api_key (e.g. planted in scraped content or stored results) replaced the client's configured key. Drop it so requests always use the client's credentials.
extract forced engine: 'extract' with a symbol key, so a string-keyed 'engine' from the call or the client defaults was sent as well (engine=google&engine=extract). Drop string-keyed engines and nil out any inherited from the defaults. extract_link now goes through extract with symbolized overrides, so it gets the same engine forcing, string-keyed overrides replace link values instead of duplicating them, and links without a url fail fast.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Let's add first-class support for the Extract API (
engine=extract), which turns any public web page into a structured JSON document and supportsscrape(default),map, andcrawlmodes.New methods
extract(params)Runs an extraction. Forces
engine: 'extract'and fails fast withSerpApiErrorwhen the required:urlparameter is missing. All other parameters (mode,max_pages,max_depth,include_subdomains,include_sitemap,device,prefetch_delay,timeout,include_tags,exclude_tags,include_markdown,include_inline_assets,output) pass through verbatim, keeping the backend as the source of truth for validation. The hash-only signature matches the gem's existing convention (search(q: ...)) and mirrors the planned Python SDK shape (client.extract(url=...)).extract_link(link, params = {})Follows a
serpapi_extract_linkembedded in Extract results (inline_links,breadcrumbs,price_offers, mapurls, crawlpages). These links carry the original request's parameters but deliberately noapi_key, so they can't be fetched raw. This method reconstructs the parameters from the link and re-issues the request through the client, applying theapi_key, defaults, timeouts, and error handling. It is mainly useful when results are detached from the request that produced them (stored JSON, Search Archive, agent pipelines). Since these links flow out of scraped web content, it rejects anything that is not aserpapi.comURL targetingengine=extract.