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
95bdb302
Commit
95bdb302
authored
May 27, 2014
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update xsoup version to release #113
parent
a5d1b56e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
+10
-6
pom.xml
pom.xml
+1
-1
MamacnPageProcessor.java
...va/us/codecraft/webmagic/samples/MamacnPageProcessor.java
+9
-5
No files found.
pom.xml
View file @
95bdb302
...
...
@@ -88,7 +88,7 @@
<dependency>
<groupId>
us.codecraft
</groupId>
<artifactId>
xsoup
</artifactId>
<version>
0.2.4
-SNAPSHOT
</version>
<version>
0.2.4
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
...
...
webmagic-samples/src/main/java/us/codecraft/webmagic/samples/MamacnPageProcessor.java
View file @
95bdb302
...
...
@@ -10,6 +10,7 @@ import us.codecraft.webmagic.selector.Selectable;
import
java.io.FileNotFoundException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.List
;
/**
* @author code4crafer@gmail.com
...
...
@@ -20,11 +21,14 @@ public class MamacnPageProcessor implements PageProcessor {
@Override
public
void
process
(
Page
page
)
{
Selectable
images
=
page
.
getHtml
().
xpath
(
"//ul[@id=ma-thumb-list]/li"
);
page
.
putField
(
"img"
,
images
.
xpath
(
"//div[@class=picList]/div[@class=pre]/div[@class=npic]//img/@src"
).
get
());
page
.
putField
(
"title"
,
page
.
getHtml
().
xpath
(
"//div[@class=picList]/div[@class=pre]/div[@class=npic]//img/@alt"
).
get
());
page
.
putField
(
"url"
,
page
.
getUrl
().
toString
());
if
(
page
.
getResultItems
().
get
(
"title"
)
==
null
)
{
List
<
Selectable
>
nodes
=
page
.
getHtml
().
xpath
(
"//ul[@id=ma-thumb-list]/li"
).
nodes
();
StringBuilder
accum
=
new
StringBuilder
();
for
(
Selectable
node
:
nodes
)
{
accum
.
append
(
"img:"
).
append
(
node
.
xpath
(
"//a/@href"
).
get
()).
append
(
"\n"
);
accum
.
append
(
"title:"
).
append
(
node
.
xpath
(
"//img/@alt"
).
get
()).
append
(
"\n"
);
}
page
.
putField
(
""
,
accum
.
toString
());
if
(
accum
.
length
()
==
0
)
{
page
.
setSkip
(
true
);
}
page
.
addTargetRequests
(
page
.
getHtml
().
links
().
regex
(
"http://www\\.mama\\.cn/photo/.*\\.html"
).
all
());
...
...
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