search
search(query: str, type: str = "search", pages: int = 1) -> Search
search(query: str, type: str = "search", pages: int = 1) -> SearchThe search method allows you to perform search queries through Google and return results for both standard web search and image search.
Parameters:
query(str): The search query string.type(str): The type of search, default is"search". You can set"images"for image search.pages(int): The number of result pages to process. Default is 1 page.
Description:
For standard web search, search returns a list of links to the found web pages and their brief descriptions.
For image search, the method retrieves links to the images.
Example Usage:
from searchx import Client
client = Client()
# Search for web pages with the query "Python programming"
search_results = client.search("Python programming")
for result in search_results:
print(f"URL: {result['url']}, Description: {result['description']}")
# Search for images with the query "cute cats"
image_results = client.search("cute cats", type="images", pages=2)
for result in image_results:
print(f"Image URL: {result['url']}")How the Method Works:
Web Search:
The method sends a GET request to Google with the specified query and collects links (url) and descriptions (description) for each result. It returns up to 10 results per page.
Image Search: The method sends a GET request to Google Images and collects image URLs. Each search page contains up to 35 images.
Note:
The method uses the
cloudscraperlibrary to bypass Cloudflare protection.The
user-agentheader is dynamically selected using thefake_useragentlibrary.
Return Value:
The method returns an instance of the Search class, containing a list of search results with url and description fields.
Last updated