Tuesday, 27 September 2011

searchr.py - inspired by catonman

I have been searching about 'how to automate searching in net' and then I found really interesting thing. I saw http://www.catonmat.net. On this site, author wrote a nice "hack" for implementing a kind of 'google-searchr code' in python. I thought about possibilities which its gave me. And thats how I wrote...

# :
# : s3archer.py @ 13.o6.2o11
# :
# : 20.o6 : dodane ua
# : 15.o6 : dodane spanie na googlu
# : 14.o5 : dodane logowanie + edit
# : 13.o5 : dodane szukanie v1
# :
# :
from xgoogle.search import GoogleSearch, SearchError # szukanie
import sys # argz
import socket # gniazda
from time import sleep # spanie na googlach
from urllib import FancyURLopener # UAaaaaaaa ;-)
if len(sys.argv) < 2:
print ‘\n-=[ searcher ]=-\n’
print ‘usage: python searcher.py what2find…\n’
gs = GoogleSearch(sys.argv[1])
gs.results_per_page = 100
results = []
while True:
tmp = gs.get_results()
for res in results:
print res.url.encode(„utf-8″) # wyswietla tylko urla
if not tmp: # brak wynikow
# wyjatki/bledy
except SearchError, e:
print „Search failed: %s” % e

Its of course just a simple example and was made for fun only. Anyway I wish You luck in python learning and programming.
- sths wrong with searching (google drop some request; sleep()?)
- make searching more ‘unix style’ – uniq to implement
- add google hacks (filetype, etc)

No comments:

Post a Comment

What do You think...?