I am trying to write a web crawler (for academic research purposes) that grabs the number of links different websites/domain names have from other websites, as listed on Google (for example, to get the number of websites linking to YouTube, you could type into Google 'Link:YouTube.c om' and get 11,100). I have a list of websites in a spreadsheet and would like to be able to output the number of links for each website in the sheet.
When I run the below script, it seems to run fast and accurately for a minute or so, or for several hundred websites. Then the crawler slows down, outputting that 0 links were found for all websites.
Am I getting this result because Google is detecting my crawler and blocking it? If so, is there anything that I can do, such as telling my crawler to sleep, and try again later (I've tried to sketch something out in the lower batch of code below)?
Thank you.
[CODE=python]
for i in range(len(lines )-1):
searchTerm = "link:"+ searchTerms[i]
br = MakeBrowser()
br.open('http://www.google.com' )
br.select_form( name='f')
br['q'] = searchTerm
resp = br.submit().rea dlines()
# Get the line number that starts with '<table'
htmlSplitter = re.compile('<.* ?>')
names=[]
y=htmlSplitter. split(resp[0])
value=''
for j in range(0,len(y)-1):
if y[j]==' linking to ':
value=string.re place(y[j-1],",","")
#...
br = MakeBrowser()
haveResp = False
while not haveResp:
try:
br.open('http://inventory.overt ure.com/d/' + \
'searchinventor y/suggestion/')
br.select_form( name='stst')
br['term'] = searchTerm
resp = br.submit().rea dlines()
haveResp = True
except urllib2.URLErro r:
time.sleep(10)[/CODE]
When I run the below script, it seems to run fast and accurately for a minute or so, or for several hundred websites. Then the crawler slows down, outputting that 0 links were found for all websites.
Am I getting this result because Google is detecting my crawler and blocking it? If so, is there anything that I can do, such as telling my crawler to sleep, and try again later (I've tried to sketch something out in the lower batch of code below)?
Thank you.
[CODE=python]
for i in range(len(lines )-1):
searchTerm = "link:"+ searchTerms[i]
br = MakeBrowser()
br.open('http://www.google.com' )
br.select_form( name='f')
br['q'] = searchTerm
resp = br.submit().rea dlines()
# Get the line number that starts with '<table'
htmlSplitter = re.compile('<.* ?>')
names=[]
y=htmlSplitter. split(resp[0])
value=''
for j in range(0,len(y)-1):
if y[j]==' linking to ':
value=string.re place(y[j-1],",","")
#...
br = MakeBrowser()
haveResp = False
while not haveResp:
try:
br.open('http://inventory.overt ure.com/d/' + \
'searchinventor y/suggestion/')
br.select_form( name='stst')
br['term'] = searchTerm
resp = br.submit().rea dlines()
haveResp = True
except urllib2.URLErro r:
time.sleep(10)[/CODE]
Comment