To get Google search results with Python 3, you can use the
googlesearch-python library. Follow the steps below to install and use it:
- Install the library:
$ pip install googlesearch-python
- Import the library in your Python script:
from googlesearch import search
- Use the search() function to get the search results:
query = "your search query"
num_results = 10 # number of results you want to get
for result in search(query, num_results=num_results, lang='en'):
Replace your search query in the query variable with your desired search query. You can also specify the num_results parameter to determine the number of search results you want.
The lang parameter allows you to specify the language of the search results. It is optional and defaults to English (en).
- Run your Python script, and it will print the URLs of the search results.
Note: Keep in mind that web scraping Google search results is against Google's terms of service. Make sure to use this library responsibly and only for educational or personal purposes.