Pattern-counter
Pattern counter or counter bot.. This is our first bot that we are going to build. And it's a simple bot which look for patterns or strings on a fetched web content. So lets start ...
Code:
import mechanize
def patterncounter(): #defining function
count=0 #declaring variable count for counting
browser = mechanize.Browser(factory=mechanize.RobustFactory())
#initialising browser
browser.set_handle_robots(False)
browser.open("http://www.minerbots.blogspot.in/") #opening URL
html = browser.response().readlines() #Fetching web contents
for i in range(0,len(html)): #Searching for pattern 'Vicz' line by line
if 'Vicz' in html[i]:
count=count+1
print "%d No of times found"%count #analyzing and producing results
Code:
import mechanize
def patterncounter(): #defining function
count=0 #declaring variable count for counting
browser = mechanize.Browser(factory=mechanize.RobustFactory())
#initialising browser
browser.set_handle_robots(False)
browser.open("http://www.minerbots.blogspot.in/") #opening URL
html = browser.response().readlines() #Fetching web contents
for i in range(0,len(html)): #Searching for pattern 'Vicz' line by line
if 'Vicz' in html[i]:
count=count+1
print "%d No of times found"%count #analyzing and producing results
This is the screen shot of output..
This counterbot count for the number of occurence of string 'Vicz' in the content fetched from URL 'http://www.minerbots.blogspot.in/'
Demo is over.. now do it youself.. ;)
No comments:
Post a Comment