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
64293cba
Commit
64293cba
authored
May 02, 2014
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
samples
parent
bc1d14fe
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
6 deletions
+46
-6
GithubRepo.java
...c/main/java/us/codecraft/webmagic/samples/GithubRepo.java
+31
-1
GithubRepoPageProcessor.java
...s/codecraft/webmagic/samples/GithubRepoPageProcessor.java
+8
-5
ReplacePipeline.java
.../codecraft/webmagic/samples/pipeline/ReplacePipeline.java
+7
-0
No files found.
webmagic-samples/src/main/java/us/codecraft/webmagic/samples/GithubRepo.java
View file @
64293cba
...
@@ -4,4 +4,34 @@ package us.codecraft.webmagic.samples;
...
@@ -4,4 +4,34 @@ package us.codecraft.webmagic.samples;
* @author code4crafer@gmail.com
* @author code4crafer@gmail.com
*/
*/
public
class
GithubRepo
{
public
class
GithubRepo
{
}
private
String
name
;
private
String
author
;
private
String
readme
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getAuthor
()
{
return
author
;
}
public
void
setAuthor
(
String
author
)
{
this
.
author
=
author
;
}
public
String
getReadme
()
{
return
readme
;
}
public
void
setReadme
(
String
readme
)
{
this
.
readme
=
readme
;
}
}
\ No newline at end of file
webmagic-samples/src/main/java/us/codecraft/webmagic/samples/GithubRepoPageProcessor.java
View file @
64293cba
...
@@ -7,7 +7,7 @@ import us.codecraft.webmagic.processor.PageProcessor;
...
@@ -7,7 +7,7 @@ import us.codecraft.webmagic.processor.PageProcessor;
/**
/**
* @author code4crafter@gmail.com <br>
* @author code4crafter@gmail.com <br>
* @since 0.
3.2
* @since 0.
5.1
*/
*/
public
class
GithubRepoPageProcessor
implements
PageProcessor
{
public
class
GithubRepoPageProcessor
implements
PageProcessor
{
...
@@ -17,13 +17,16 @@ public class GithubRepoPageProcessor implements PageProcessor {
...
@@ -17,13 +17,16 @@ public class GithubRepoPageProcessor implements PageProcessor {
public
void
process
(
Page
page
)
{
public
void
process
(
Page
page
)
{
page
.
addTargetRequests
(
page
.
getHtml
().
links
().
regex
(
"(https://github\\.com/\\w+/\\w+)"
).
all
());
page
.
addTargetRequests
(
page
.
getHtml
().
links
().
regex
(
"(https://github\\.com/\\w+/\\w+)"
).
all
());
page
.
addTargetRequests
(
page
.
getHtml
().
links
().
regex
(
"(https://github\\.com/\\w+)"
).
all
());
page
.
addTargetRequests
(
page
.
getHtml
().
links
().
regex
(
"(https://github\\.com/\\w+)"
).
all
());
page
.
putField
(
"author"
,
page
.
getUrl
().
regex
(
"https://github\\.com/(\\w+)/.*"
).
toString
());
GithubRepo
githubRepo
=
new
GithubRepo
();
page
.
putField
(
"name"
,
page
.
getHtml
().
xpath
(
"//h1[@class='entry-title public']/strong/a/text()"
).
toString
());
githubRepo
.
setAuthor
(
page
.
getUrl
().
regex
(
"https://github\\.com/(\\w+)/.*"
).
toString
());
if
(
page
.
getResultItems
().
get
(
"name"
)==
null
){
githubRepo
.
setName
(
page
.
getHtml
().
xpath
(
"//h1[@class='entry-title public']/strong/a/text()"
).
toString
());
githubRepo
.
setReadme
(
page
.
getHtml
().
xpath
(
"//div[@id='readme']/tidyText()"
).
toString
());
if
(
githubRepo
.
getName
()
==
null
)
{
//skip this page
//skip this page
page
.
setSkip
(
true
);
page
.
setSkip
(
true
);
}
else
{
page
.
putField
(
"repo"
,
githubRepo
);
}
}
page
.
putField
(
"readme"
,
page
.
getHtml
().
xpath
(
"//div[@id='readme']/tidyText()"
));
}
}
@Override
@Override
...
...
webmagic-samples/src/main/java/us/codecraft/webmagic/samples/pipeline/ReplacePipeline.java
0 → 100644
View file @
64293cba
package
us
.
codecraft
.
webmagic
.
samples
.
pipeline
;
/**
* @author code4crafer@gmail.com
*/
public
class
ReplacePipeline
{
}
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