我们有一个 Python 库来获取和解析 Google 搜索结果,可在此处访问:https ://github.com/serpapi/google-search-results-python
from lib.google_search_results import GoogleSearchResults
query = GoogleSearchResults({"q": "coffee"})
html_results = query.get_html()
它目前仅适用于 SerpApi.com 后端,但可以随意扩展它以支持更多后端。
更全面的选择:
query_params = {
"q": "query",
"google_domain": "Google Domain",
"location": "Location Requested",
"device": device,
"hl": "Google UI Language",
"gl": "Google Country",
"safe": "Safe Search Flag",
"num": "Number of Results",
"start": "Pagination Offset",
"serp_api_key": "Your SERP API Key"
}
query = GoogleSearchResults(query_params)
query.params_dict["location"] = "Portland"
html_results = query.get_html()
dictionary_results = query.get_dictionary()
dictionary_results_with_images = query.get_dictionary_with_images()
json_results = query.get_json()
json_results_with_images = query.get_json_with_images()