Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webmagic
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
webmagic
Commits
c6132e07
Commit
c6132e07
authored
Aug 07, 2013
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some refector
parent
194152ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
17 deletions
+28
-17
QuickStarter.java
...rc/main/java/us/codecraft/webmagic/main/QuickStarter.java
+28
-17
No files found.
webmagic-samples/src/main/java/us/codecraft/webmagic/main/QuickStarter.java
View file @
c6132e07
...
@@ -19,34 +19,29 @@ import java.util.Scanner;
...
@@ -19,34 +19,29 @@ import java.util.Scanner;
*/
*/
public
class
QuickStarter
{
public
class
QuickStarter
{
public
static
void
main
(
String
[]
args
)
{
private
static
Map
<
String
,
Class
>
clazzMap
;
Map
<
String
,
Class
>
clazzMap
=
new
LinkedHashMap
<
String
,
Class
>();
private
static
Map
<
String
,
String
>
urlMap
;
private
static
void
init
(){
clazzMap
=
new
LinkedHashMap
<
String
,
Class
>();
clazzMap
.
put
(
"1"
,
OschinaBlog
.
class
);
clazzMap
.
put
(
"1"
,
OschinaBlog
.
class
);
clazzMap
.
put
(
"2"
,
IteyeBlog
.
class
);
clazzMap
.
put
(
"2"
,
IteyeBlog
.
class
);
clazzMap
.
put
(
"3"
,
News163
.
class
);
clazzMap
.
put
(
"3"
,
News163
.
class
);
Map
<
String
,
String
>
urlMap
=
new
LinkedHashMap
<
String
,
String
>();
urlMap
=
new
LinkedHashMap
<
String
,
String
>();
urlMap
.
put
(
"1"
,
"http://my.oschina.net/flashsword/blog"
);
urlMap
.
put
(
"1"
,
"http://my.oschina.net/flashsword/blog"
);
urlMap
.
put
(
"2"
,
"http://flashsword20.iteye.com/"
);
urlMap
.
put
(
"2"
,
"http://flashsword20.iteye.com/"
);
urlMap
.
put
(
"3"
,
"http://news.163.com/"
);
urlMap
.
put
(
"3"
,
"http://news.163.com/"
);
Scanner
stdin
=
new
Scanner
(
System
.
in
);
}
public
static
void
main
(
String
[]
args
)
{
init
();
String
key
=
null
;
String
key
=
null
;
System
.
out
.
println
(
"Choose a Spider demo:"
);
key
=
readKey
(
key
);
for
(
Map
.
Entry
<
String
,
Class
>
classEntry
:
clazzMap
.
entrySet
())
{
System
.
out
.
println
(
classEntry
.
getKey
()+
"\t"
+
classEntry
.
getValue
()
+
"\t"
+
urlMap
.
get
(
classEntry
.
getKey
()));
}
while
(
key
==
null
)
{
key
=
new
String
(
stdin
.
nextLine
());
if
(
clazzMap
.
get
(
key
)
==
null
)
{
System
.
out
.
println
(
"Invalid choice!"
);
key
=
null
;
}
}
System
.
out
.
println
(
"The demo started and will last 20 seconds..."
);
System
.
out
.
println
(
"The demo started and will last 20 seconds..."
);
//Start spider
//Start spider
OOSpider
.
create
(
Site
.
me
().
addStartUrl
(
urlMap
.
get
(
key
)),
clazzMap
.
get
(
key
)).
pipeline
(
new
PagedPipeline
()).
pipeline
(
new
ConsolePipeline
()).
runAsync
();
OOSpider
.
create
(
Site
.
me
().
addStartUrl
(
urlMap
.
get
(
key
)),
clazzMap
.
get
(
key
)).
pipeline
(
new
PagedPipeline
()).
pipeline
(
new
ConsolePipeline
()).
runAsync
();
try
{
try
{
Thread
.
sleep
(
20000
);
Thread
.
sleep
(
20000
);
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
...
@@ -56,4 +51,20 @@ public class QuickStarter {
...
@@ -56,4 +51,20 @@ public class QuickStarter {
System
.
out
.
println
(
"To more usage, try to customize your own Spider!"
);
System
.
out
.
println
(
"To more usage, try to customize your own Spider!"
);
System
.
exit
(
0
);
System
.
exit
(
0
);
}
}
private
static
String
readKey
(
String
key
)
{
Scanner
stdin
=
new
Scanner
(
System
.
in
);
System
.
out
.
println
(
"Choose a Spider demo:"
);
for
(
Map
.
Entry
<
String
,
Class
>
classEntry
:
clazzMap
.
entrySet
())
{
System
.
out
.
println
(
classEntry
.
getKey
()+
"\t"
+
classEntry
.
getValue
()
+
"\t"
+
urlMap
.
get
(
classEntry
.
getKey
()));
}
while
(
key
==
null
)
{
key
=
new
String
(
stdin
.
nextLine
());
if
(
clazzMap
.
get
(
key
)
==
null
)
{
System
.
out
.
println
(
"Invalid choice!"
);
key
=
null
;
}
}
return
key
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment