Comments (2)
@jvmvik Can you take a look?
from google-search-results-python.
@samuelhaysom Currently, the best approach would be to use serpapi_pagination
instead as you also mentioned in #25 issue. When #30 is merged, the pagination()
method would be the preferred one. Sorry for such a long reply.
if "next" in results.get("serpapi_pagination", {}):
search.params_dict.update(dict(parse_qsl(urlsplit(results.get("serpapi_pagination").get("next")).query)))
else:
break
For example:
# Google Scholar Search API
from serpapi import GoogleSearch
from urllib.parse import (parse_qsl, urlsplit)
params = {
"api_key": "...", # serpapi api key
"engine": "google_scholar", # search engine
"q": "minecraft redstone", # language
"hl": "en" # search query
}
search = GoogleSearch(params) # where data extraction happens
# to show page number
page_num = 0
# iterate over all pages
results_is_present = True
while results_is_present:
results = search.get_dict() # JSON -> Python dict
if "error" in results:
print(results["error"])
break
page_num += 1
print(f"Current page: {page_num}")
# iterate over organic results and extract the data
for result in results.get("organic_results", []):
print(result.get("position"), result.get("title"), sep="\n")
# check if the next page key is present in the JSON
# if present -> split URL in parts and update to the next page
if "next" in results.get("serpapi_pagination", {}):
search.params_dict.update(dict(parse_qsl(urlsplit(results.get("serpapi_pagination").get("next")).query)))
else:
break
from google-search-results-python.
Related Issues (20)
- Cannot increase the offset between returned results using pagination HOT 2
- google scholar pagination not returning final results page HOT 9
- Does the api need money to provide service? HOT 1
- how to resolve the Connection aborted error when calling the serpapi HOT 4
- [Google Jobs API] Support for Pagination HOT 1
- "error": "Missing query `q` parameter." HOT 7
- How to get "related articles" links from google scholar via serpapi? HOT 3
- [Pagination] Pagination isn't correct and it skips index by one HOT 1
- [Version] Update PyPi to include the most up-to-date version HOT 3
- Setting Timeout on Instantiation for GoogleSearch HOT 3
- .. HOT 2
- AttributeError during the import of the module: `initialized module 'serpapi' has no attribute 'GoogleSearch' (most likely due to a circular import)` HOT 5
- Exception not handled on SerpApiClient.get_json HOT 1
- [Feature Request] Add Async Implementation HOT 5
- [Discuss] Wrapper longer response times caused by some overhead/additional processing
- [Feature request] Make `async: True` do everything under the hood HOT 1
- How to add proxy and ssl certs while using the Search API? I am currently trying to access it via my corporate network. HOT 1
- requests.exceptions.SSLError: HTTPSConnectionPool(host='serpapi.com', port=443) HOT 1
- Python package should not include tests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-search-results-python.