-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpiderTest.java
76 lines (65 loc) · 2.08 KB
/
SpiderTest.java
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
67
68
69
70
71
72
73
74
75
76
package com.ucr.cs172.project.crawler;
import java.lang.Thread;
// Object to hold command line arguments
class ComandArguments {
public String seedFilePath;
public int maxHopDistance;
}
public class SpiderTest
{
public static void main(String[] args)
{
ComandArguments commandArgs = new ComandArguments();
getArguments(commandArgs," ", 2, args);
Spider spider = new Spider(commandArgs.seedFilePath, commandArgs.maxHopDistance);
spider.getUrlSeeds(commandArgs.seedFilePath);
spider.testSeedInit();
int listSize = spider.listSize();
for(int i = 0; i < listSize; i++)
{
try
{
while( spider.getQueueArrayList().get(i).size() > 0)
{
String temp = spider.nextUrl(i);
if(temp.length() > 0)
{
if((i+1) < listSize )
{
spider.crawl(temp, i+1);
//Thread.sleep(1000);
}
else
{
spider.crawl(temp, -1);
//Thread.sleep(1000);
}
}
}
}
catch(Exception e){ System.out.println("Interrupted");}
}
} // End main()
public static void getArguments (ComandArguments arguments, String defaultFilePath,
int defaultMaxHops, String[] args)
{
if (args.length == 0 || args.length == 1) {
System.out.println("*****************************************************");
System.out.println("* No or too few arguments for seedFilePath and *");
System.out.println("* maxHopsDistance provided using default arguments. *");
System.out.println("*****************************************************");;
arguments.seedFilePath = defaultFilePath;
arguments.maxHopDistance = defaultMaxHops;
} else {
arguments.seedFilePath = args[0];
// convert string to int
int maxHops = defaultMaxHops;
try {
maxHops = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
System.out.println("Conversion from string to integer error.");
}
arguments.maxHopDistance = maxHops;
}
} // End getArguments()
}