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
18a3af4a
Commit
18a3af4a
authored
Nov 28, 2013
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more sample for jsonpath #42
parent
59ad4cad
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
0 deletions
+84
-0
AppStore.java
...src/main/java/us/codecraft/webmagic/example/AppStore.java
+12
-0
GithubRepoApi.java
...ain/java/us/codecraft/webmagic/example/GithubRepoApi.java
+70
-0
JsonPathSelector.java
...java/us/codecraft/webmagic/selector/JsonPathSelector.java
+2
-0
No files found.
webmagic-extension/src/main/java/us/codecraft/webmagic/example/AppStore.java
View file @
18a3af4a
...
...
@@ -3,11 +3,15 @@ package us.codecraft.webmagic.example;
import
us.codecraft.webmagic.Site
;
import
us.codecraft.webmagic.model.OOSpider
;
import
us.codecraft.webmagic.model.annotation.ExtractBy
;
import
us.codecraft.webmagic.utils.Experimental
;
import
java.util.List
;
/**
* @author code4crafter@gmail.com
* @since 0.4.1
*/
@Experimental
public
class
AppStore
{
@ExtractBy
(
type
=
ExtractBy
.
Type
.
JsonPath
,
value
=
"$..trackName"
)
...
...
@@ -16,9 +20,17 @@ public class AppStore {
@ExtractBy
(
type
=
ExtractBy
.
Type
.
JsonPath
,
value
=
"$..description"
)
private
String
description
;
@ExtractBy
(
type
=
ExtractBy
.
Type
.
JsonPath
,
value
=
"$..userRatingCount"
)
private
int
userRatingCount
;
@ExtractBy
(
type
=
ExtractBy
.
Type
.
JsonPath
,
value
=
"$..screenshotUrls"
,
multi
=
true
)
private
List
<
String
>
screenshotUrls
;
public
static
void
main
(
String
[]
args
)
{
AppStore
appStore
=
OOSpider
.
create
(
Site
.
me
(),
AppStore
.
class
).<
AppStore
>
get
(
"http://itunes.apple.com/lookup?id=653350791&country=cn&entity=software"
);
System
.
out
.
println
(
appStore
.
trackName
);
System
.
out
.
println
(
appStore
.
description
);
System
.
out
.
println
(
appStore
.
userRatingCount
);
System
.
out
.
println
(
appStore
.
screenshotUrls
);
}
}
webmagic-extension/src/main/java/us/codecraft/webmagic/example/GithubRepoApi.java
0 → 100644
View file @
18a3af4a
package
us
.
codecraft
.
webmagic
.
example
;
import
us.codecraft.webmagic.Site
;
import
us.codecraft.webmagic.model.ConsolePageModelPipeline
;
import
us.codecraft.webmagic.model.HasKey
;
import
us.codecraft.webmagic.model.OOSpider
;
import
us.codecraft.webmagic.model.annotation.ExtractBy
;
import
us.codecraft.webmagic.model.annotation.ExtractByUrl
;
import
java.util.List
;
/**
* @author code4crafter@gmail.com <br>
* @since 0.4.1
*/
public
class
GithubRepoApi
implements
HasKey
{
@ExtractBy
(
type
=
ExtractBy
.
Type
.
JsonPath
,
value
=
"$.name"
)
private
String
name
;
@ExtractBy
(
type
=
ExtractBy
.
Type
.
JsonPath
,
value
=
"$..owner.login"
)
private
String
author
;
@ExtractBy
(
type
=
ExtractBy
.
Type
.
JsonPath
,
value
=
"$.language"
,
multi
=
true
)
private
List
<
String
>
language
;
@ExtractBy
(
type
=
ExtractBy
.
Type
.
JsonPath
,
value
=
"$.stargazers_count"
)
private
int
star
;
@ExtractBy
(
type
=
ExtractBy
.
Type
.
JsonPath
,
value
=
"$.forks_count"
)
private
int
fork
;
@ExtractByUrl
private
String
url
;
public
static
void
main
(
String
[]
args
)
{
OOSpider
.
create
(
Site
.
me
().
setSleepTime
(
100
)
,
new
ConsolePageModelPipeline
(),
GithubRepoApi
.
class
)
.
addUrl
(
"https://api.github.com/repos/code4craft/webmagic"
).
run
();
}
@Override
public
String
key
()
{
return
author
+
":"
+
name
;
}
public
String
getName
()
{
return
name
;
}
public
String
getAuthor
()
{
return
author
;
}
public
List
<
String
>
getLanguage
()
{
return
language
;
}
public
String
getUrl
()
{
return
url
;
}
public
int
getStar
()
{
return
star
;
}
public
int
getFork
()
{
return
fork
;
}
}
webmagic-extension/src/main/java/us/codecraft/webmagic/selector/JsonPathSelector.java
View file @
18a3af4a
package
us
.
codecraft
.
webmagic
.
selector
;
import
com.jayway.jsonpath.JsonPath
;
import
us.codecraft.webmagic.utils.Experimental
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -12,6 +13,7 @@ import java.util.List;
* @author code4crafter@gmail.com <br>
* @since 0.2.1
*/
@Experimental
public
class
JsonPathSelector
implements
Selector
{
private
String
jsonPathStr
;
...
...
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