我正在使用谷歌搜索 API 从谷歌搜索中提取信息并显示它并将其保存在控制台中
我有错误,因为代码没有进入 for 循环
这是代码:
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
这是控制台的输出
>>> runfile('D:/Search Engine/SearchEngine.py', wdir='D:/Search
Engine')
In Try
results done
>>>