forked from skru/JOEGLE_web_crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Joegle.py
70 lines (41 loc) · 1.66 KB
/
Joegle.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from crawler import crawl_web
from search import lucky_search, ordered_search, easy_search
from webcorpus import WebCorpus
import json
import requests
######################################################
# COMMENT THIS SECTION OUT AFTER RUNNING THE FIRST TIME
# try and think of a page that has shit loads of external links
seed = ['http://www.dmoz.org/']
d = {'tocrawl':seed}
with open('tocrawl_json.json', 'w') as outfile:
json.dump(d, outfile)
d = {'crawled':[]}
with open('crawled_json.json', 'w') as outfile:
json.dump(d, outfile)
######################################################
count = 0
maxc = 50000
while count < maxc:
print 'crawling web'
data_file = open('tocrawl_json.json', 'r')
data = json.load(data_file)
url = data['tocrawl']
crawled_data_file = open('crawled_json.json', 'r')
crawled_data = json.load(crawled_data_file)
crawled = crawled_data['crawled']
pages_crawled = len(crawled)
print pages_crawled
corpus = crawl_web(url,3,crawled)
print 'crawled'
### After the crawler has done its shizzle it sends the data as JSON to my site
### feel free to uncomment but i don't know how much data the server can recieve at once,
### also it might be too much for Mysql to handle at once'
#json_corpus = corpus.to_JSON()
#print 'saving corpus to server'
#url = "http://www.josephmohan.co.uk/crawler/json_reciever"
#datatosend = json_corpus
#headers = {'content-type': 'application/json'}
#r = requests.post(url, data=json.dumps(json_corpus), headers=headers, timeout=60*10)
#jsoner.put(json_corpus,"json_response.json")
count+=1