#!/usr/bin/env python
#-*- coding: utf-8 -*-
import sys, datetime, urllib2, re
if len(sys.argv) != 2:
hits={'link':'http://www.google.de/'}
else:
paramurl = sys.argv[1]
if not paramurl.startswith('http://'):
paramurl = 'http://%s' % paramurl
hits={'link':'' + paramurl + ''}
url='http://google.com/search?' # Set web search URL
# Generate web search term
hits['web search term']=urllib2.quote('link:'+hits['link'])
# Execute web search
urlstr='%sq=%s'%(url,hits['web search term'])
url=urllib2.Request(urlstr)
url.add_header('User-Agent','')
url=urllib2.urlopen(url).read()
# Store date and time of web search
hits['datetimeutc']=datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
# Parse web search results to determine hits
hits['hits']=re.search('Results 1 - 10 of about (?P.+?)',url)
if hits['hits']!=None:
hits['hits']=hits['hits'].group('hits')
hits['hits']=hits['hits'].replace(',','')
hits['hits']=int(hits['hits'])
else:
hits['hits']=0
print "Backlinks: %d\tURL: %s" % (int(hits['hits']), paramurl)