playing with pyGoogle - strange codec error

Brian Blazer brian at brianandkate.com
Tue Apr 5 14:11:56 EDT 2005


On 2005-04-04 10:06:23 -0500, Brian Blazer <brian at brianandkate.com> said:

<snip>

You know, I am beginning to think that I MAY have stumbled on a bug 
here.  At first I was thinking that this issue was related to the 
offending character being out of range for the Mac.  Then I tried it on 
A MS machine and a linux box; all with the same error.

This does not happen when I wrote the same script in java.  This is 
making me wonder if there is an issue with the wrapper for the google 
api that was originally done in java.

For the sake of it, here is the full code (minus my google key).  It is 
going to look wierd, but those print statements are there so that I 
dont have to open the file it is writing to every time I want to see 
stuff.  it has my name hard coded into the search query.  The commented 
r.snippet.encode(mac_roman) was there to see if by changing the 
encoding, I could make it work (no luck).  I also tried putting

 #-*- coding: utf-8 -*-

right after the shebang (as listed here: 
http://www.python.org/peps/pep-0263.html).  Again, no help.

Anyway, here is the code ------------------------>

import google

google.LICENSE_KEY = 'insertKeyHere'
#print google.doSpellingSuggestion('helllo')
data = google.doGoogleSearch('Brian Blazer')
print 'Found %d results' % len(data.results)

searchData = open('searchData.txt','w')

for r in data.results:
#    r.snippet.encode('mac_roman')
    searchData.write ('Title: ' + r.title + '\n' + '\n')
    searchData.write ('URL: ' + r.URL + '\n' + '\n')
    searchData.write ('Snippet: ' + r.snippet + '\n' + '\n'+'\n')
    print r.URL
    print r.title
    print r.snippet



-- 
Nail a post to the Spalted Board. Free WW'ing software and forums.  
Regular freebies! http://www.spaltedboard.com




More information about the Python-list mailing list