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
516ff331
Commit
516ff331
authored
Aug 02, 2013
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add failfast
parent
7ee567b8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
2 deletions
+7
-2
ExtractBy.java
...main/java/us/codecraft/webmagic/annotation/ExtractBy.java
+2
-0
PageModelExtractor.java
.../us/codecraft/webmagic/annotation/PageModelExtractor.java
+3
-0
IteyeBlog.java
...a/us/codecraft/webmagic/annotation/samples/IteyeBlog.java
+2
-2
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/annotation/ExtractBy.java
View file @
516ff331
...
...
@@ -13,6 +13,8 @@ import java.lang.annotation.Target;
@Target
({
ElementType
.
FIELD
})
public
@interface
ExtractBy
{
//TODO: add list support
String
value
();
public
enum
Type
{
XPath
,
Regex
,
Css
};
...
...
webmagic-core/src/main/java/us/codecraft/webmagic/annotation/PageModelExtractor.java
View file @
516ff331
...
...
@@ -42,6 +42,9 @@ class PageModelExtractor {
fieldExtractors
=
new
ArrayList
<
FieldExtractor
>();
for
(
Field
field
:
clazz
.
getDeclaredFields
())
{
field
.
setAccessible
(
true
);
if
(!
field
.
getType
().
isAssignableFrom
(
String
.
class
)){
throw
new
IllegalStateException
(
"Field "
+
field
.
getName
()+
" must be string"
);
}
ExtractBy
extractBy
=
field
.
getAnnotation
(
ExtractBy
.
class
);
if
(
extractBy
!=
null
)
{
String
value
=
extractBy
.
value
();
...
...
webmagic-samples/src/main/java/us/codecraft/webmagic/annotation/samples/IteyeBlog.java
View file @
516ff331
...
...
@@ -14,7 +14,7 @@ import us.codecraft.webmagic.annotation.TargetUrl;
public
class
IteyeBlog
implements
Blog
{
@ExtractBy
(
"//title"
)
private
String
title
;
private
int
title
;
@ExtractBy
(
value
=
"div#blog_content"
,
type
=
ExtractBy
.
Type
.
Css
)
private
String
content
;
...
...
@@ -32,7 +32,7 @@ public class IteyeBlog implements Blog{
}
public
String
getTitle
()
{
return
title
;
return
null
;
}
public
String
getContent
()
{
...
...
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