Skip to content

Add native Extract API support - #37

Open
strzibny wants to merge 2 commits into
serpapi:masterfrom
strzibny:extract-api
Open

strzibny wants to merge 2 commits into
serpapi:masterfrom
strzibny:extract-api

Conversation

@strzibny

@strzibny strzibny commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Let's 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.

The new extract(params) method

Runs an extraction. Forces engine: 'extract' and fails fast with SerpApiError 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, 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=...)).

client = SerpApi::Client.new(api_key: ENV['SERPAPI_KEY'])

results = client.extract(url: 'https://example.com/')
pp results[:page_information]

results = client.extract(url: 'https://books.toscrape.com/', mode: 'crawl', max_pages: 3, max_depth: 1)
pp results[:pages]

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 extract and extract_link helpers.
  • 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.

Comment thread lib/serpapi/client.rb Outdated
Comment thread lib/serpapi/client.rb Outdated
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 method 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.

Includes offline unit specs, live example specs, a runnable demo
(demo/demo_extract.rb), and README documentation.
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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The localized implementation and focused specs support the intended behavior, with no unresolved review findings; tests were not executed.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@adarshdigievo adarshdigievo left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @strzibny
This looks good to merge. But recommend moving to a new branch in the repo for the test suite to run before the merge.

Checks done

  • AI reviews: GPT6 Astra xhigh and Opus 5.5 high flagged no issues.
  • Manual tests passed for all 3 modes: scrape, crawl, and map. All worked as expected with live requests.

@adarshdigievo
adarshdigievo self-requested a review October 27, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants