ejes consulting

Techincal Consulting Design and Automation

googleit.py

leave a comment »

#!/usr/local/bin/python

import re,sys,os,urllib

if len(sys.argv)==1:
        print ‘Usage:\n%s “search term”\n’ % sys.argv[0]

url=’http://www.google.ca/search?q=’+urllib.quote(sys.argv%5B1%5D)+’&start=0&ie=utf-8&oe=utf-8&hl=xx-hacker&btnI=I%27m+Feeling+Lucky’

(cin,cout,cerr)=os.popen3(‘lynx -accept_all_cookies -dump ‘+url)
now=findit=0
for lines in cout.readlines():
        if re.compile(‘^[ ]+[0-9]+[.] ‘).search(lines):
                if not ‘google’ in lines:
                        outme=re.sub(‘(^[ ]*[0-9]+[.] |\r?\n)’,”,lines)
                        print outme
                        sys.exit(0)

Advertisements

Written by ejes

August 24, 2009 at 12:25 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: