I'm using google search API to extract information from the google search and displaying it as well as saving it in the console
I'm having error, as the code is not going into the for loop
Here is the code:
import csv
from xgoogle.search import GoogleSearch,SearchError
try:
print("In Try ")
gs = GoogleSearch(' Mercedes Benz')
gs.results_per_page=10
results=gs.get_results()
print" results done "
for res in results:
print(" In For Loop")
urll=res.url.encode("utf-8")
titles= res.title.encode("utf-8")
descs= res.desc.encode("utf-8")
print urll
print titles
print descs
# c.writerow[(urll,descs,titles)[]
try:
with open('sample.csv', 'wb') as csvfile:
we = csv.writer(csvfile, delimiter=',')
we.writerow[(urll,titles,descs)]
print " Finished"
except Exception:
print" Not Finished"
except SearchError, e:
print " Search Failed : %s" %e
Here is the output from the console
>>> runfile('D:/Search Engine/SearchEngine.py', wdir='D:/Search
Engine')
In Try
results done
>>>