forked from youerning/UserPyScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpider.py
More file actions
31 lines (28 loc) · 943 Bytes
/
Copy pathSpider.py
File metadata and controls
31 lines (28 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#coding:utf8
import Handler
class spider(object):
"""docstring for spider"""
def __init__(self, url):
self.url = [url]
self.urlManager = Handler.urlManager()
self.output = Handler.Output()
self.download = Handler.Download()
self.parser = Handler.Parser()
def crawl(self, size=100):
count = 0
self.urlManager.add(self.url)
while len(self.urlManager.new_urls):
try:
url = self.urlManager.get()
cont = self.download.download(url)
urls, data = self.parser.parser(url, cont)
self.urlManager.add(urls)
self.output.add(data)
if count > size:
break
count += 1
print "url: %s crawled" % url
except Exception as e:
print "crawl faild"
print e
self.output.save()