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
5c96407a
Commit
5c96407a
authored
Aug 06, 2013
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix a null domain error
parent
f4134504
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
Site.java
webmagic-core/src/main/java/us/codecraft/webmagic/Site.java
+13
-1
OschinaBlog.java
...java/us/codecraft/webmagic/model/samples/OschinaBlog.java
+3
-1
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/Site.java
View file @
5c96407a
package
us
.
codecraft
.
webmagic
;
import
us.codecraft.webmagic.utils.UrlUtils
;
import
java.util.*
;
/**
...
...
@@ -90,6 +92,11 @@ public class Site {
* @return 已设置的domain
*/
public
String
getDomain
()
{
if
(
domain
==
null
)
{
if
(
startUrls
.
size
()
>
0
)
{
domain
=
UrlUtils
.
getDomain
(
startUrls
.
get
(
0
));
}
}
return
domain
;
}
...
...
@@ -150,6 +157,7 @@ public class Site {
/**
* 获取初始页面的地址列表
*
* @return 初始页面的地址列表
*/
public
List
<
String
>
getStartUrls
()
{
...
...
@@ -158,6 +166,7 @@ public class Site {
/**
* 增加初始页面的地址,可反复调用此方法增加多个初始地址。
*
* @param startUrl 初始页面的地址
* @return this
*/
...
...
@@ -179,6 +188,7 @@ public class Site {
/**
* 获取两次抓取之间的间隔
*
* @return 两次抓取之间的间隔,单位毫秒
*/
public
int
getSleepTime
()
{
...
...
@@ -187,6 +197,7 @@ public class Site {
/**
* 获取重新下载的次数,默认为0
*
* @return 重新下载的次数
*/
public
int
getRetryTimes
()
{
...
...
@@ -195,6 +206,7 @@ public class Site {
/**
* 设置获取重新下载的次数,默认为0
*
* @return this
*/
public
Site
setRetryTimes
(
int
retryTimes
)
{
...
...
@@ -219,7 +231,7 @@ public class Site {
return
true
;
}
public
Task
toTask
(){
public
Task
toTask
()
{
return
new
Task
()
{
@Override
public
String
getUUID
()
{
...
...
webmagic-samples/src/main/java/us/codecraft/webmagic/model/samples/OschinaBlog.java
View file @
5c96407a
...
...
@@ -4,6 +4,8 @@ import us.codecraft.webmagic.Site;
import
us.codecraft.webmagic.model.ExtractBy
;
import
us.codecraft.webmagic.model.OOSpider
;
import
us.codecraft.webmagic.model.TargetUrl
;
import
us.codecraft.webmagic.pipeline.ConsolePipeline
;
import
us.codecraft.webmagic.pipeline.JsonFilePipeline
;
/**
* @author code4crafter@gmail.com <br>
...
...
@@ -28,7 +30,7 @@ public class OschinaBlog implements Blog{
}
public
static
void
main
(
String
[]
args
)
{
OOSpider
.
create
(
Site
.
me
().
addStartUrl
(
"http://my.oschina.net/flashsword/blog"
),
OschinaBlog
.
class
).
run
();
OOSpider
.
create
(
Site
.
me
().
addStartUrl
(
"http://my.oschina.net/flashsword/blog"
),
OschinaBlog
.
class
).
pipeline
(
new
ConsolePipeline
()).
pipeline
(
new
JsonFilePipeline
()).
run
();
}
public
String
getTitle
()
{
...
...
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