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
bc1d14fe
Commit
bc1d14fe
authored
May 02, 2014
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sample
parent
8e4814bd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
GithubRepo.java
...c/main/java/us/codecraft/webmagic/samples/GithubRepo.java
+7
-0
GithubRepoPageProcessor.java
...s/codecraft/webmagic/samples/GithubRepoPageProcessor.java
+37
-0
No files found.
webmagic-samples/src/main/java/us/codecraft/webmagic/samples/GithubRepo.java
0 → 100644
View file @
bc1d14fe
package
us
.
codecraft
.
webmagic
.
samples
;
/**
* @author code4crafer@gmail.com
*/
public
class
GithubRepo
{
}
webmagic-samples/src/main/java/us/codecraft/webmagic/samples/GithubRepoPageProcessor.java
0 → 100644
View file @
bc1d14fe
package
us
.
codecraft
.
webmagic
.
samples
;
import
us.codecraft.webmagic.Page
;
import
us.codecraft.webmagic.Site
;
import
us.codecraft.webmagic.Spider
;
import
us.codecraft.webmagic.processor.PageProcessor
;
/**
* @author code4crafter@gmail.com <br>
* @since 0.3.2
*/
public
class
GithubRepoPageProcessor
implements
PageProcessor
{
private
Site
site
=
Site
.
me
().
setRetryTimes
(
3
).
setSleepTime
(
0
);
@Override
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+)"
).
all
());
page
.
putField
(
"author"
,
page
.
getUrl
().
regex
(
"https://github\\.com/(\\w+)/.*"
).
toString
());
page
.
putField
(
"name"
,
page
.
getHtml
().
xpath
(
"//h1[@class='entry-title public']/strong/a/text()"
).
toString
());
if
(
page
.
getResultItems
().
get
(
"name"
)==
null
){
//skip this page
page
.
setSkip
(
true
);
}
page
.
putField
(
"readme"
,
page
.
getHtml
().
xpath
(
"//div[@id='readme']/tidyText()"
));
}
@Override
public
Site
getSite
()
{
return
site
;
}
public
static
void
main
(
String
[]
args
)
{
Spider
.
create
(
new
GithubRepoPageProcessor
()).
addUrl
(
"https://github.com/code4craft"
).
thread
(
5
).
run
();
}
}
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