Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (0)

Powered by Vanilla. Made with Bootstrap.
Python Googleapis Ajax
  • Xin
    Posts: 3,251
    http://ajax.googleapis.com/ajax/service ... /web?v=1.0

    Im using this as shown in chronic's post but i cant find any documention on it, i've got it working but it only shows like 5 or 6 urls when i need it to show 100s any one know a solution?
    Xin
  • Xin
    Posts: 3,251
    This is majorly annoying me now :L, i've managed to get up to 50 results with a loop but it wont let me get any more than that :S.
    Xin
  • chroniccommand
    Posts: 1,389
    Straight from twisted's google example:

    # Copyright (c) 2001-2004 Twisted Matrix Laboratories.
    # See LICENSE for details.

    #
    \"\"\"\\"I'm Feeling Lucky\\" with U{Google<http://google.com>}.
    \"\"\"
    import urllib
    from twisted.internet import protocol, reactor, defer
    from twisted.web import http

    class GoogleChecker(http.HTTPClient):

    def connectionMade(self):
    self.sendCommand('GET', self.factory.url)
    self.sendHeader('Host', self.factory.host)
    self.sendHeader('User-Agent', self.factory.agent)
    self.endHeaders()

    def handleHeader(self, key, value):
    key = key.lower()
    if key == 'location':
    self.factory.gotLocation(value)

    def handleStatus(self, version, status, message):
    if status != '302':
    self.factory.noLocation(ValueError(\"bad status\"))

    def handleEndHeaders(self):
    self.factory.noLocation(ValueError(\"no location\"))

    def handleResponsePart(self, part):
    pass

    def handleResponseEnd(self):
    pass

    def connectionLost(self, reason):
    self.factory.noLocation(reason)


    class GoogleCheckerFactory(protocol.ClientFactory):

    protocol = GoogleChecker

    def __init__(self, words):
    self.url = ('/search?q=%s&btnI=%s' %
    (urllib.quote_plus(' '.join(words)),
    urllib.quote_plus(\"I'm Feeling Lucky\")))
    self.agent=\"Twisted/GoogleChecker\"
    self.host = \"www.google.com\"
    self.deferred = defer.Deferred()

    def clientConnectionFailed(self, _, reason):
    self.noLocation(reason)

    def gotLocation(self, location):
    if self.deferred:
    self.deferred.callback(location)
    self.deferred = None

    def noLocation(self, error):
    if self.deferred:
    self.deferred.errback(error)
    self.deferred = None


    def checkGoogle(words):
    \"\"\"Check google for a match.

    @returns: a Deferred which will callback with a URL or errback with a
    Failure.
    \"\"\"
    factory = GoogleCheckerFactory(words)
    reactor.connectTCP('www.google.com', 80, factory)
    return factory.deferred
  • Xin
    Posts: 3,251
    That source doesnt return the urls just goes to the imfeeling lucky one chronic
    Xin
  • chroniccommand
    Posts: 1,389
    said:


    That source doesnt return the urls just goes to the imfeeling lucky one chronic



    My bad. Try this:
    http://www.catonmat.net/blog/python-lib ... le-search/
  • Xin
    Posts: 3,251
    said:


    said:


    That source doesnt return the urls just goes to the imfeeling lucky one chronic



    My bad. Try this:
    http://www.catonmat.net/blog/python-lib ... le-search/


    Il check it out thanks, however if i use this, and want to distribute the program does that mean it wont work for people that dont have xgoogle
    Xin
  • chroniccommand
    Posts: 1,389
    said:


    said:


    said:


    That source doesnt return the urls just goes to the imfeeling lucky one chronic



    My bad. Try this:
    http://www.catonmat.net/blog/python-lib ... le-search/


    Il check it out thanks, however if i use this, and want to distribute the program does that mean it wont work for people that dont have xgoogle

    You could always include the module in the zipped up package. But I'm not much of an expert on the google API.
  • Xin
    Posts: 3,251
    Okay sounds cool, il work on making my own lighter version built into the program
    Xin