-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawler1.py
57 lines (32 loc) · 1.16 KB
/
crawler1.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
import os
def create_project_directory(directory):
if not os.path.exists(directory):
print('Creating Project ' + directory)
os.makedirs(directory)
def write_file(filename , data):
f = open(filename , 'w')
f.write(data)
f.close()
def create_datafiles(directory , url):
queue = directory + "/queue" +".txt" #List of links waiting to be crawled
crawled = directory + "/crawled" + ".txt"
if not os.path.isfile(queue):
write_file(queue , url)
if not os.path.isfile(crawled):
write_file(crawled , "")
def append_to_file(filename , data):
f = open(filename , 'a')
f.write(data + "\n")
f.close()
def del_file(filename):
f = open(filename , 'w')
def file_to_set(filename):
result = set()
f = open(filename , 'rt')
for line in f:
result.add(line.replace('\n' ,'')) #Removing newline from url
return result
def set_to_file(result , filename):
del_file(filename)
for link in result:
append_to_file(filename , link)