Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching in Google with Python

Tags:

I want to search a text in Google using a python script and return the name, description and URL for each result. I'm currently using this code:

from google import search  ip=raw_input("What would you like to search for? ")  for url in search(ip, stop=20):      print(url) 

This returns only the URL's. How can I return the name and description for each URL?

like image 761
Yarden Avatar asked Jul 28 '16 11:07

Yarden


People also ask

Can you use Python to search Google?

googlesearch is a Python library for searching Google, easily. googlesearch uses requests and BeautifulSoup4 to scrape Google.


1 Answers

I assume you are using this library by Mario Vilas because of the stop=20 argument which appears in his code. It seems like this library is not able to return anything but the URLs, making it horribly undeveloped. As such, what you want to do is not possible with the library you are currently using.

I would suggest you instead use abenassi/Google-Search-API. Then you can simply do:

from google import google num_page = 3 search_results = google.search("This is my query", num_page) for result in search_results:     print(result.description) 
like image 106
Jokab Avatar answered Oct 16 '22 10:10

Jokab