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
b3a282e5
Commit
b3a282e5
authored
Jun 09, 2014
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some fix for tests #130
parent
b75e64a6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
305 additions
and
320 deletions
+305
-320
Site.java
webmagic-core/src/main/java/us/codecraft/webmagic/Site.java
+6
-1
HttpClientDownloader.java
...s/codecraft/webmagic/downloader/HttpClientDownloader.java
+2
-2
ProxyPool.java
.../src/main/java/us/codecraft/webmagic/proxy/ProxyPool.java
+293
-306
ProxyTest.java
.../src/test/java/us/codecraft/webmagic/proxy/ProxyTest.java
+4
-11
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/Site.java
View file @
b3a282e5
...
@@ -49,7 +49,7 @@ public class Site {
...
@@ -49,7 +49,7 @@ public class Site {
private
HttpHost
httpProxy
;
private
HttpHost
httpProxy
;
private
ProxyPool
httpProxyPool
=
new
ProxyPool
()
;
private
ProxyPool
httpProxyPool
;
private
boolean
useGzip
=
true
;
private
boolean
useGzip
=
true
;
...
@@ -453,6 +453,11 @@ public class Site {
...
@@ -453,6 +453,11 @@ public class Site {
return
this
;
return
this
;
}
}
public
Site
enableHttpProxyPool
()
{
this
.
httpProxyPool
=
new
ProxyPool
();
return
this
;
}
public
ProxyPool
getHttpProxyPool
()
{
public
ProxyPool
getHttpProxyPool
()
{
return
httpProxyPool
;
return
httpProxyPool
;
}
}
...
...
webmagic-core/src/main/java/us/codecraft/webmagic/downloader/HttpClientDownloader.java
View file @
b3a282e5
...
@@ -141,7 +141,7 @@ public class HttpClientDownloader extends AbstractDownloader {
...
@@ -141,7 +141,7 @@ public class HttpClientDownloader extends AbstractDownloader {
.
setSocketTimeout
(
site
.
getTimeOut
())
.
setSocketTimeout
(
site
.
getTimeOut
())
.
setConnectTimeout
(
site
.
getTimeOut
())
.
setConnectTimeout
(
site
.
getTimeOut
())
.
setCookieSpec
(
CookieSpecs
.
BEST_MATCH
);
.
setCookieSpec
(
CookieSpecs
.
BEST_MATCH
);
if
(
site
.
getHttpProxyPool
().
isEnable
())
{
if
(
site
.
getHttpProxyPool
()
!=
null
&&
site
.
getHttpProxyPool
().
isEnable
())
{
HttpHost
host
=
site
.
getHttpProxyFromPool
();
HttpHost
host
=
site
.
getHttpProxyFromPool
();
requestConfigBuilder
.
setProxy
(
host
);
requestConfigBuilder
.
setProxy
(
host
);
request
.
putExtra
(
Request
.
PROXY
,
host
);
request
.
putExtra
(
Request
.
PROXY
,
host
);
...
...
webmagic-core/src/main/java/us/codecraft/webmagic/proxy/ProxyPool.java
View file @
b3a282e5
package
us
.
codecraft
.
webmagic
.
proxy
;
package
us
.
codecraft
.
webmagic
.
proxy
;
import
java.io.File
;
import
org.apache.http.HttpHost
;
import
java.io.FileInputStream
;
import
org.slf4j.Logger
;
import
java.io.FileNotFoundException
;
import
org.slf4j.LoggerFactory
;
import
java.io.FileOutputStream
;
import
us.codecraft.webmagic.utils.FilePersistentBase
;
import
java.io.IOException
;
import
us.codecraft.webmagic.utils.ProxyUtils
;
import
java.io.ObjectInputStream
;
import
java.io.
ObjectOutputStream
;
import
java.io.
*
;
import
java.net.InetAddress
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.net.UnknownHostException
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.NoSuchElementException
;
import
java.util.Timer
;
import
java.util.TimerTask
;
import
java.util.Map.Entry
;
import
java.util.Map.Entry
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.BlockingQueue
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.DelayQueue
;
import
java.util.concurrent.DelayQueue
;
import
org.apache.http.HttpHost
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
us.codecraft.webmagic.utils.FilePersistentBase
;
import
us.codecraft.webmagic.utils.ProxyUtils
;
/**
/**
* Pooled Proxy Object
* Pooled Proxy Object
*
*
* @author yxssfxwzy@sina.com <br>
* @author yxssfxwzy@sina.com <br>
* @since 0.5.1
* @see Proxy
* @see Proxy
* @since 0.5.1
*/
*/
public
class
ProxyPool
{
public
class
ProxyPool
{
...
@@ -87,9 +74,9 @@ public class ProxyPool {
...
@@ -87,9 +74,9 @@ public class ProxyPool {
private
void
setFilePath
()
{
private
void
setFilePath
()
{
String
tmpDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
String
tmpDir
=
System
.
getProperty
(
"java.io.tmpdir"
);
String
path
=
tmpDir
+
"webmagic\\
lastUse.proxy"
;
String
path
=
tmpDir
+
FilePersistentBase
.
PATH_SEPERATOR
+
"webmagic"
+
FilePersistentBase
.
PATH_SEPERATOR
+
"
lastUse.proxy"
;
if
(
tmpDir
!=
null
&&
new
File
(
tmpDir
).
isDirectory
())
{
if
(
tmpDir
!=
null
&&
new
File
(
tmpDir
).
isDirectory
())
{
fBase
.
setPath
(
tmpDir
+
"webmagic"
);
fBase
.
setPath
(
tmpDir
+
FilePersistentBase
.
PATH_SEPERATOR
+
"webmagic"
);
File
f
=
fBase
.
getFile
(
path
);
File
f
=
fBase
.
getFile
(
path
);
if
(!
f
.
exists
())
{
if
(!
f
.
exists
())
{
try
{
try
{
...
...
webmagic-core/src/test/java/us/codecraft/webmagic/proxy/ProxyTest.java
View file @
b3a282e5
package
us
.
codecraft
.
webmagic
.
proxy
;
package
us
.
codecraft
.
webmagic
.
proxy
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
org.apache.http.HttpHost
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.io.File
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
org.apache.http.HttpHost
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
us.codecraft.webmagic.Request
;
/**
/**
* @author yxssfxwzy@sina.com May 30, 2014
* @author yxssfxwzy@sina.com May 30, 2014
...
@@ -30,11 +28,6 @@ public class ProxyTest {
...
@@ -30,11 +28,6 @@ public class ProxyTest {
}
}
}
}
@Test
public
void
testAddProxy
()
{
}
@Test
@Test
public
void
testProxy
()
{
public
void
testProxy
()
{
ProxyPool
proxyPool
=
new
ProxyPool
(
httpProxyList
);
ProxyPool
proxyPool
=
new
ProxyPool
(
httpProxyList
);
...
...
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