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
7038c00a
Commit
7038c00a
authored
Apr 01, 2014
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reformat
parent
6252042e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
48 deletions
+48
-48
README.md
README.md
+48
-48
No files found.
README.md
View file @
7038c00a
...
...
@@ -22,27 +22,27 @@
Add dependencies to your pom.xml:
```
xml
<dependency>
<groupId>
us.codecraft
</groupId>
<artifactId>
webmagic-core
</artifactId>
<version>
0.4.3
</version>
</dependency>
<dependency>
<groupId>
us.codecraft
</groupId>
<artifactId>
webmagic-extension
</artifactId>
<version>
0.4.3
</version>
</dependency>
<dependency>
<groupId>
us.codecraft
</groupId>
<artifactId>
webmagic-core
</artifactId>
<version>
0.4.3
</version>
</dependency>
<dependency>
<groupId>
us.codecraft
</groupId>
<artifactId>
webmagic-extension
</artifactId>
<version>
0.4.3
</version>
</dependency>
```
WebMagic use slf4j with slf4j-log4j12 implementation. If you customized your slf4j implementation, please exclude slf4j-log4j12.
```
xml
<exclusions>
<exclusion>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-log4j12
</artifactId>
</exclusion>
</exclusions>
<exclusions>
<exclusion>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-log4j12
</artifactId>
</exclusion>
</exclusions>
```
...
...
@@ -53,30 +53,30 @@ WebMagic use slf4j with slf4j-log4j12 implementation. If you customized your slf
Write a class implements PageProcessor:
```
java
public
class
OschinaBlogPageProcesser
implements
PageProcessor
{
public
class
OschinaBlogPageProcesser
implements
PageProcessor
{
private
Site
site
=
Site
.
me
().
setDomain
(
"my.oschina.net"
);
private
Site
site
=
Site
.
me
().
setDomain
(
"my.oschina.net"
);
@Override
public
void
process
(
Page
page
)
{
List
<
String
>
links
=
page
.
getHtml
().
links
().
regex
(
"http://my\\.oschina\\.net/flashsword/blog/\\d+"
).
all
();
page
.
addTargetRequests
(
links
);
page
.
putField
(
"title"
,
page
.
getHtml
().
xpath
(
"//div[@class='BlogEntity']/div[@class='BlogTitle']/h1"
).
toString
());
page
.
putField
(
"content"
,
page
.
getHtml
().
$
(
"div.content"
).
toString
());
page
.
putField
(
"tags"
,
page
.
getHtml
().
xpath
(
"//div[@class='BlogTags']/a/text()"
).
all
());
}
@Override
public
void
process
(
Page
page
)
{
List
<
String
>
links
=
page
.
getHtml
().
links
().
regex
(
"http://my\\.oschina\\.net/flashsword/blog/\\d+"
).
all
();
page
.
addTargetRequests
(
links
);
page
.
putField
(
"title"
,
page
.
getHtml
().
xpath
(
"//div[@class='BlogEntity']/div[@class='BlogTitle']/h1"
).
toString
());
page
.
putField
(
"content"
,
page
.
getHtml
().
$
(
"div.content"
).
toString
());
page
.
putField
(
"tags"
,
page
.
getHtml
().
xpath
(
"//div[@class='BlogTags']/a/text()"
).
all
());
}
@Override
public
Site
getSite
()
{
return
site
;
@Override
public
Site
getSite
()
{
return
site
;
}
}
public
static
void
main
(
String
[]
args
)
{
Spider
.
create
(
new
OschinaBlogPageProcesser
()).
addUrl
(
"http://my.oschina.net/flashsword/blog"
)
.
addPipeline
(
new
ConsolePipeline
()).
run
();
}
public
static
void
main
(
String
[]
args
)
{
Spider
.
create
(
new
OschinaBlogPageProcesser
()).
addUrl
(
"http://my.oschina.net/flashsword/blog"
)
.
addPipeline
(
new
ConsolePipeline
()).
run
();
}
}
```
*
`page.addTargetRequests(links)`
...
...
@@ -86,24 +86,24 @@ Write a class implements PageProcessor:
You can also use annotation way:
```
java
@TargetUrl
(
"http://my.oschina.net/flashsword/blog/\\d+"
)
public
class
OschinaBlog
{
@TargetUrl
(
"http://my.oschina.net/flashsword/blog/\\d+"
)
public
class
OschinaBlog
{
@ExtractBy
(
"//title"
)
private
String
title
;
@ExtractBy
(
"//title"
)
private
String
title
;
@ExtractBy
(
value
=
"div.BlogContent"
,
type
=
ExtractBy
.
Type
.
Css
)
private
String
content
;
@ExtractBy
(
value
=
"div.BlogContent"
,
type
=
ExtractBy
.
Type
.
Css
)
private
String
content
;
@ExtractBy
(
value
=
"//div[@class='BlogTags']/a/text()"
,
multi
=
true
)
private
List
<
String
>
tags
;
@ExtractBy
(
value
=
"//div[@class='BlogTags']/a/text()"
,
multi
=
true
)
private
List
<
String
>
tags
;
public
static
void
main
(
String
[]
args
)
{
OOSpider
.
create
(
Site
.
me
(),
new
ConsolePageModelPipeline
(),
OschinaBlog
.
class
).
addUrl
(
"http://my.oschina.net/flashsword/blog"
).
run
();
}
}
public
static
void
main
(
String
[]
args
)
{
OOSpider
.
create
(
Site
.
me
(),
new
ConsolePageModelPipeline
(),
OschinaBlog
.
class
).
addUrl
(
"http://my.oschina.net/flashsword/blog"
).
run
();
}
}
```
### Docs and samples:
...
...
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