Hello,
I am playing with the google api and soap. I have the newest version
of soap and i think ruby 1.8. I created my code on a laptop with
mandrake 10.2 with the same version of ruby and soap. On my laptop it
works fine. On my windows computer it give me an error.
"F:\Documents and Settings\iv\Desktop\googlerip>ruby googled.rb
monkey filetype:
pdf
Loading compatibility library...
c:/ruby/lib/ruby/1.8/xsd/datatypes.rb:172:in `_set': {http://www.w3.org/2001/XML
Schema}string: cannot accept '<b>...</b> Tibetan year of the <b>monkey</b>. Thes
e instructions are traditionally given <b>...</b><br> thus will give the rare Γ
ÇÖ<b>Monkey</b>-Year-TeachingsΓÇÖ after the inauguration in <b>...</b>'. (XSD::V
alueSpaceError)
from c:/ruby/lib/ruby/1.8/xsd/datatypes.rb:114:in `set'
from c:/ruby/lib/ruby/1.8/soap/encodingstyle/soapHandler.rb:453:in `deco
de_textbuf'
from c:/ruby/lib/ruby/1.8/soap/encodingstyle/soapHandler.rb:214:in `deco
de_tag_end'
from c:/ruby/lib/ruby/1.8/soap/parser.rb:185:in `decode_tag_end'
from c:/ruby/lib/ruby/1.8/soap/parser.rb:146:in `end_element'
from c:/ruby/lib/ruby/1.8/xsd/xmlparser/parser.rb:75:in `end_element'
from c:/ruby/lib/ruby/1.8/xsd/xmlparser/xmlparser.rb:36:in `do_parse'
from c:/ruby/lib/ruby/1.8/xsd/xmlparser/xmlparser.rb:31:in `parse'
... 7 levels...
from (eval):2:in `doGoogleSearch'
from googled.rb:16
from googled.rb:15:in `each'
from googled.rb:15"
I am working off an example i found on the internet. Here is my code:
require "soap/driver"
ENDPOINT = 'http://api.google.com/search/beta2'
NS = 'urn:GoogleSearch'
KEY = "Enter_your_Key"
fail "Missing query args" if ARGV.empty?
query = ARGV.join(" ")
soap = SOAP::Driver.new(nil, nil, NS, ENDPOINT)
soap.addMethodWithSOAPAction(
'doGoogleSearch', NS, 'key', 'q', 'start', 'maxResults', 'filter',
'restrict', 'safeSearch', 'lr', 'ie', 'oe')
i=0
for i in 0..90
res = soap.doGoogleSearch(
KEY, query, i, 10, false, nil, false, nil, 'latin1', 'latin1')
puts "Estimated result count: " + res.estimatedTotalResultsCount
puts "Searched in:" + res.searchTime + " seconds"
puts "Index start:" + res.startIndex
puts "Index End:" + res.endIndex
res.resultElements.each do |entry|
puts
puts entry.URL
puts
filename=entry.URL.gsub("//", '').gsub("~", '').gsub("/", '')
if(!(FileTest.exist?(filename))) then
aFile = File.new(filename, "w+")
aFile.puts Net::HTTP.get(URI.parse(entry.URL))
puts entry.snippet
end
end
i=i+9
end
Am i missing something on my windows computer?
Becker