You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7f2dec3
Browse filesBrowse the repository at this point in the historyBrowse files
* chore: add Python 3.15 support in CI and pyproject.toml
* feat: add `client.extract` dedicated method for Extract API
* docs: align Extract examples and tests with current API
Document direct Markdown output and current JSON fields, and consolidate
Extract coverage into one test file. Correct the documentation validator
for successful empty Google pagination responses and refresh examples.
Co-authored-by: Codex <codex@openai.com>
---------
Co-authored-by: Codex <codex@openai.com>
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Bug reports and pull requests are welcome on GitHub. Run commands from the repos
4
4
5
5
## Development setup
6
6
7
-
Use Python 3.13 to work on the package and its documentation. The SDK CI also tests Python 3.8 through 3.14. Create a virtual environment and install the package with its test and documentation dependencies:
7
+
The SDK CI tests Python 3.8 through 3.15. Create a virtual environment and install the package with its test and documentation dependencies:
8
8
9
9
```sh
10
10
uv venv --python 3.13
@@ -31,10 +31,10 @@ The commands below use `python` from that environment.
31
31
32
32
### Checks that need no API key
33
33
34
-
These tests cover response parsing, image uploads with simulated responses, timeouts, exceptions, documentation syntax, and the example runner:
34
+
These tests cover response parsing, image uploads and extraction with simulated responses, timeouts, exceptions, documentation syntax, and the example runner:
The file list limits this command to tests that make no external requests. Applying `-k 'not live'` to the entire suite is not enough to run offline: some SDK integration tests do not have `live` in their names.
@@ -61,7 +61,7 @@ This includes live account, location, search, and pagination checks. To run ever
61
61
python -m pytest -q
62
62
```
63
63
64
-
Both commands make real SerpApi requests. The full suite can use more searches than a test run limited to the files you changed. PR CI also runs the standalone engine examples on Python 3.14. Documentation tests run in the package and documentation release workflows on release tags, and in manual documentation runs on `master`.
64
+
Both commands make real SerpApi requests. The full suite can use more searches than a test run limited to the files you changed. PR CI also runs the standalone engine examples on Python 3.15. Documentation tests run in the package and documentation release workflows on release tags, and in manual documentation runs on `master`.
Copy file name to clipboardExpand all lines: README.md
+62-5Lines changed: 62 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,48 @@ Environment variables are a secure, safe, and easy way to manage secrets.
45
45
Set `export SERPAPI_KEY=<secret_serpapi_key>` in your shell.
46
46
Python accesses these variables from `os.environ["SERPAPI_KEY"]`.
47
47
48
+
### Extract content from a URL
49
+
50
+
The [Extract API](https://serpapi.com/extract-api) supports single-page scraping, URL discovery, and crawling. Call `client.extract()` with a parameter dictionary or keyword arguments. The client sets `engine="extract"` automatically.
51
+
52
+
Set `output="md"` to get the page's main content as a Markdown string:
Crawl mode can consume one search credit per successfully extracted page, including the starting page. Set `max_pages` to limit the number of pages.
87
+
88
+
See the [Extract API guide](https://github.com/serpapi/serpapi-python/blob/master/docs/user_guide/extract.md) for response examples and more options.
89
+
48
90
### Error handling
49
91
50
92
Unsuccessful requests raise `serpapi.HTTPError` or `serpapi.TimeoutError` exceptions. The returned status code will reflect the sort of error that occurred, please refer to [Status and Error Codes Documentation](https://serpapi.com/api-status-and-error-codes) for more details.
@@ -267,15 +309,30 @@ results = client.search({
267
309
- API Documentation: [serpapi.com/google-autocomplete-api](https://serpapi.com/google-autocomplete-api)
268
310
269
311
### Search Google Immersive Product
312
+
313
+
Get a current `page_token` from Google Shopping before requesting product details:
Copy file name to clipboardExpand all lines: docs/index.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,6 +90,7 @@ Use the same search parameter names as the [SerpApi API documentation](https://s
90
90
-[Getting Started](user_guide/getting-started.md) covers installation and your first search. [Client Usage](user_guide/client-usage.md) explains how to make requests and read responses.
91
91
-[AI Agents](ai-agents.md) covers search tools, Markdown results, and API references for agents.
92
92
-[Output Formats](user_guide/output-formats.md) explains when to use JSON, Markdown, or HTML.
93
+
-[Extract API](user_guide/extract.md) covers page content in Markdown or JSON, URL discovery, and crawling.
93
94
-[Migration Guide](user_guide/migrating-from-google-search-results.md) shows how to replace `google-search-results` with this package.
94
95
-[Parameters and Engines](user_guide/parameters-and-engines.md) explains search parameters and how to test them in the [SerpApi Playground](https://serpapi.com/playground).
95
96
- For scripts that collect results, see [pagination](user_guide/pagination.md), [timeouts and errors](user_guide/errors-and-timeouts.md), [request options](user_guide/request-options.md), and [account and locations](user_guide/account-and-locations.md).
Copy file name to clipboardExpand all lines: docs/user_guide/client-usage.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -148,10 +148,13 @@ For one additional page, call `next_page()`:
148
148
next_results = results.next_page()
149
149
```
150
150
151
-
Use `yield_pages()` in a loop to read the current page and fetch more pages. This example stops after ten pages, or earlier if there is no next page:
151
+
Use `yield_pages()` in a loop to read the current page and fetch more pages. This example reads up to ten pages and stops if a page contains an `error` message:
152
152
153
153
```python
154
154
for page_number, page inenumerate(results.yield_pages(max_pages=10), start=1):
155
+
if"error"in page:
156
+
print(page["error"])
157
+
break
155
158
current = page.get("serpapi_pagination", {}).get("current", page_number)
description: "Extract page content, discover URLs, and crawl websites with the Python client."
4
+
---
5
+
6
+
# Extract API
7
+
8
+
Use `client.extract()` to read content from a public URL. It supports single-page scraping, URL discovery, and crawling. Pass a parameter dictionary or keyword arguments, as you would with `client.search()`. The client sets `engine="extract"` automatically.
9
+
10
+
See the [Extract API documentation](https://serpapi.com/extract-api) for all parameters and response fields.
11
+
12
+
## Get Page Content as Markdown
13
+
14
+
Set `output="md"` to get the page's main content as a Markdown string.
15
+
16
+
After [setting your API key](getting-started.md#installation), run:
You can pass the returned string to an AI agent or save it to a file.
32
+
33
+
## Get Structured Data as JSON
34
+
35
+
JSON is the default output format. The SDK returns a dictionary-like `SerpResults` object with page information, meta tags, structured data, links, images, and Markdown. The sections returned depend on the target page.
The `markdown` field contains the page's main content. Set `include_markdown=False` to omit it from the JSON response.
45
+
46
+
The module-level `serpapi.extract(url=..., api_key=...)` function accepts the same parameters.
47
+
48
+
## Get HTML
49
+
50
+
Set `output="html"` to get the retrieved HTML as a string:
51
+
52
+
```python
53
+
html = client.extract(url="https://serpapi.com/", output="html")
54
+
```
55
+
56
+
## Discover URLs
57
+
58
+
Set `mode="map"` to discover URLs on a website:
59
+
60
+
```python
61
+
results = client.extract(
62
+
url="https://serpapi.com/",
63
+
mode="map",
64
+
include_sitemap=False,
65
+
include_subdomains=False,
66
+
)
67
+
68
+
for entry in results["urls"]:
69
+
print(entry["url"])
70
+
```
71
+
72
+
Map mode includes sitemap URLs by default. Set `include_sitemap=False` to discover URLs from the page's links only. Set `include_subdomains=True` to include subdomains.
73
+
74
+
## Crawl Multiple Pages
75
+
76
+
Set `mode="crawl"` to follow links and extract pages:
77
+
78
+
```python
79
+
results = client.extract(
80
+
url="https://serpapi.com/",
81
+
mode="crawl",
82
+
max_pages=2,
83
+
max_depth=1,
84
+
timeout=180,
85
+
)
86
+
87
+
for page in results["pages"]:
88
+
print(page["url"])
89
+
print(page["markdown"])
90
+
```
91
+
92
+
Each entry in `results["pages"]` contains the extracted page's data, including its `markdown` field. The starting page has depth `0`. `max_pages` includes the starting page and defaults to `10`. Each successfully extracted page can consume one search credit. Set a page limit for your crawl and allow enough time for the HTTP request to finish.
93
+
94
+
For requests you want to retrieve later, pass `"async": True` in a parameter dictionary and use the [Search Archive](async-search-archive.md).
95
+
96
+
## Timeouts and Content Filters
97
+
98
+
The `timeout=` keyword sets the SDK's HTTP timeout in seconds. Set it above the API fetch timeout, and allow time for all pages when crawling. Put the Extract API's fetch timeout in the parameter dictionary to send it in milliseconds:
Use `include_tags` and `exclude_tags` to keep or remove content with CSS selectors, such as `include_tags="article, main"` or `exclude_tags="nav, footer"`. See the [Extract API parameters](https://serpapi.com/extract-api) for details and [Errors and Timeouts](errors-and-timeouts.md) for exception handling.
:param params: Optional mapping of Extract API parameters, including the required ``url``. Put ``timeout`` here to set the API fetch timeout in milliseconds.
71
+
:param kwargs: Additional API parameters or HTTP request options, as in :meth:`search`. The ``timeout`` keyword controls the HTTP client timeout in seconds.
72
+
73
+
``mode`` accepts ``scrape`` (default), ``map``, or ``crawl``. ``output`` accepts ``json`` (default), ``html``, or ``md``.
74
+
JSON includes page content in the top-level ``markdown`` field by default,
75
+
or in each ``pages`` entry for crawls. Set ``include_markdown=False`` to omit it.
76
+
For a scraped page, ``output="md"`` returns the page Markdown without search metadata.
77
+
78
+
Crawl mode can consume one search credit per successfully extracted page. Use ``max_pages`` to limit the number of pages.
0 commit comments