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
6b9d21fc
Commit
6b9d21fc
authored
Jan 22, 2015
by
Yihua Huang
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #188 from EdwardsBean/retry_time
add retry sleep time
parents
8ffc1a70
49786656
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
22 deletions
+38
-22
Site.java
webmagic-core/src/main/java/us/codecraft/webmagic/Site.java
+36
-20
Spider.java
...agic-core/src/main/java/us/codecraft/webmagic/Spider.java
+2
-2
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/Site.java
View file @
6b9d21fc
...
@@ -39,6 +39,8 @@ public class Site {
...
@@ -39,6 +39,8 @@ public class Site {
private
int
cycleRetryTimes
=
0
;
private
int
cycleRetryTimes
=
0
;
private
int
retrySleepTime
=
1000
;
private
int
timeOut
=
5000
;
private
int
timeOut
=
5000
;
private
static
final
Set
<
Integer
>
DEFAULT_STATUS_CODE_SET
=
new
HashSet
<
Integer
>();
private
static
final
Set
<
Integer
>
DEFAULT_STATUS_CODE_SET
=
new
HashSet
<
Integer
>();
...
@@ -49,8 +51,8 @@ public class Site {
...
@@ -49,8 +51,8 @@ public class Site {
private
HttpHost
httpProxy
;
private
HttpHost
httpProxy
;
private
ProxyPool
httpProxyPool
;
private
ProxyPool
httpProxyPool
;
private
boolean
useGzip
=
true
;
private
boolean
useGzip
=
true
;
/**
/**
...
@@ -359,6 +361,20 @@ public class Site {
...
@@ -359,6 +361,20 @@ public class Site {
return
useGzip
;
return
useGzip
;
}
}
public
int
getRetrySleepTime
()
{
return
retrySleepTime
;
}
/**
* Set retry sleep times when download fail, 1000 by default. <br>
*
* @param retrySleepTime
*/
public
Site
setRetrySleepTime
(
int
retrySleepTime
)
{
this
.
retrySleepTime
=
retrySleepTime
;
return
this
;
}
/**
/**
* Whether use gzip. <br>
* Whether use gzip. <br>
* Default is true, you can set it to false to disable gzip.
* Default is true, you can set it to false to disable gzip.
...
@@ -448,31 +464,31 @@ public class Site {
...
@@ -448,31 +464,31 @@ public class Site {
*
*
* @return this
* @return this
*/
*/
public
Site
setHttpProxyPool
(
List
<
String
[]>
httpProxyList
)
{
public
Site
setHttpProxyPool
(
List
<
String
[]>
httpProxyList
)
{
this
.
httpProxyPool
=
new
ProxyPool
(
httpProxyList
);
this
.
httpProxyPool
=
new
ProxyPool
(
httpProxyList
);
return
this
;
return
this
;
}
}
public
Site
enableHttpProxyPool
()
{
public
Site
enableHttpProxyPool
()
{
this
.
httpProxyPool
=
new
ProxyPool
();
this
.
httpProxyPool
=
new
ProxyPool
();
return
this
;
return
this
;
}
}
public
ProxyPool
getHttpProxyPool
()
{
public
ProxyPool
getHttpProxyPool
()
{
return
httpProxyPool
;
return
httpProxyPool
;
}
}
public
HttpHost
getHttpProxyFromPool
()
{
public
HttpHost
getHttpProxyFromPool
()
{
return
httpProxyPool
.
getProxy
();
return
httpProxyPool
.
getProxy
();
}
}
public
void
returnHttpProxyToPool
(
HttpHost
proxy
,
int
statusCode
)
{
public
void
returnHttpProxyToPool
(
HttpHost
proxy
,
int
statusCode
)
{
httpProxyPool
.
returnProxy
(
proxy
,
statusCode
);
httpProxyPool
.
returnProxy
(
proxy
,
statusCode
);
}
}
public
Site
setProxyReuseInterval
(
int
reuseInterval
)
{
public
Site
setProxyReuseInterval
(
int
reuseInterval
)
{
this
.
httpProxyPool
.
setReuseInterval
(
reuseInterval
);
this
.
httpProxyPool
.
setReuseInterval
(
reuseInterval
);
return
this
;
return
this
;
}
}
}
}
webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java
View file @
6b9d21fc
...
@@ -407,14 +407,14 @@ public class Spider implements Runnable, Task {
...
@@ -407,14 +407,14 @@ public class Spider implements Runnable, Task {
protected
void
processRequest
(
Request
request
)
{
protected
void
processRequest
(
Request
request
)
{
Page
page
=
downloader
.
download
(
request
,
this
);
Page
page
=
downloader
.
download
(
request
,
this
);
if
(
page
==
null
)
{
if
(
page
==
null
)
{
sleep
(
site
.
getSleepTime
());
sleep
(
site
.
get
Retry
SleepTime
());
onError
(
request
);
onError
(
request
);
return
;
return
;
}
}
// for cycle retry
// for cycle retry
if
(
page
.
isNeedCycleRetry
())
{
if
(
page
.
isNeedCycleRetry
())
{
extractAndAddRequests
(
page
,
true
);
extractAndAddRequests
(
page
,
true
);
sleep
(
site
.
getSleepTime
());
sleep
(
site
.
get
Retry
SleepTime
());
return
;
return
;
}
}
pageProcessor
.
process
(
page
);
pageProcessor
.
process
(
page
);
...
...
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