Skip to content

Commit

Permalink
Merge pull request #9 from serpapi/serpapi-client-yield-pages-documen…
Browse files Browse the repository at this point in the history
…tation

Clarify the `serpapi.Client` usage requirement for the `yield_pages` documentation
  • Loading branch information
Kenneth Reitz committed Oct 6, 2023
2 parents 5bdd865 + f0b5661 commit 16bcfa7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. serapi-python documentation master file, created by
.. serpapi-python documentation master file, created by
sphinx-quickstart on Sun Apr 3 21:09:40 2022.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Expand Down Expand Up @@ -37,6 +37,11 @@ For example, the API endpoint ``https://serpapi.com/search.json`` is represented
Any parameters that you pass to ``search()`` will be passed to the API. This includes the ``api_key`` parameter, which is required for all requests.

.. _using-api-client-directly:

Using the API Client directly
^^^^^^^^^

To make this less repetitive, and gain the benefit of connection pooling, let's start using the API Client directly::

>>> client = serpapi.Client(api_key="secret_api_key")
Expand Down Expand Up @@ -116,9 +121,11 @@ You can get the next page of results::
>>> type(s.next_page())
<class 'serpapi.models.SerpResults'>

Or iterate over all pages of results::
To iterate over all pages of results, it's recommended to :ref:`use the API Client directly <using-api-client-directly>`::

>>> for page in s.yield_pages():
>>> client = serpapi.Client(api_key="secret_api_key")
>>> search = client.search(q="Coffee", engine="google", location="Austin, Texas", hl="en", gl="us")
>>> for page in search.yield_pages():
... print(page["search_metadata"]["page_number"])
1
2
Expand Down

0 comments on commit 16bcfa7

Please sign in to comment.