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
6535928d
Commit
6535928d
authored
Mar 29, 2018
by
shenjunlin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加上超时机制
parent
b051f3e9
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
26 additions
and
24 deletions
+26
-24
pom.xml
pom.xml
+1
-1
pom.xml
webmagic-core/pom.xml
+1
-1
pom.xml
webmagic-extension/pom.xml
+1
-1
SeleniumDownloader.java
.../us/codecraft/webmagic/downloader/SeleniumDownloader.java
+4
-1
WebDriverPool.java
.../java/us/codecraft/webmagic/downloader/WebDriverPool.java
+2
-5
pom.xml
webmagic-samples/pom.xml
+1
-1
WeiboTopSpider.java
...in/java/us/codecraft/webmagic/samples/WeiboTopSpider.java
+14
-12
pom.xml
webmagic-saxon/pom.xml
+1
-1
pom.xml
webmagic-scripts/pom.xml
+1
-1
No files found.
pom.xml
View file @
6535928d
...
...
@@ -6,7 +6,7 @@
<version>
7
</version>
</parent>
<groupId>
us.codecraft.duiba
</groupId>
<version>
0.8.
0
-SNAPSHOT
</version>
<version>
0.8.
1
-SNAPSHOT
</version>
<modelVersion>
4.0.0
</modelVersion>
<packaging>
pom
</packaging>
<properties>
...
...
webmagic-core/pom.xml
View file @
6535928d
...
...
@@ -3,7 +3,7 @@
<parent>
<groupId>
us.codecraft.duiba
</groupId>
<artifactId>
webmagic-parent
</artifactId>
<version>
0.8.
0
-SNAPSHOT
</version>
<version>
0.8.
1
-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
webmagic-extension/pom.xml
View file @
6535928d
...
...
@@ -3,7 +3,7 @@
<parent>
<groupId>
us.codecraft.duiba
</groupId>
<artifactId>
webmagic-parent
</artifactId>
<version>
0.8.
0
-SNAPSHOT
</version>
<version>
0.8.
1
-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
webmagic-extension/src/main/java/us/codecraft/webmagic/downloader/SeleniumDownloader.java
View file @
6535928d
...
...
@@ -21,6 +21,7 @@ import us.codecraft.webmagic.selector.PlainText;
import
java.io.Closeable
;
import
java.io.IOException
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
/**
...
...
@@ -45,7 +46,7 @@ public class SeleniumDownloader implements Downloader, Closeable {
private
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
private
int
sleepTime
=
2
0
;
private
int
sleepTime
=
10
0
;
private
int
poolSize
=
1
;
...
...
@@ -136,6 +137,7 @@ public class SeleniumDownloader implements Downloader, Closeable {
private
Page
downLoadPage
(
WebDriver
webDriver
,
Task
task
,
Request
request
){
logger
.
info
(
"downloading page "
+
request
.
getUrl
());
try
{
webDriver
.
manage
().
timeouts
().
pageLoadTimeout
(
10
,
TimeUnit
.
SECONDS
);
webDriver
.
get
(
request
.
getUrl
());
Thread
.
sleep
(
sleepTime
);
}
catch
(
Exception
e
)
{
...
...
@@ -144,6 +146,7 @@ public class SeleniumDownloader implements Downloader, Closeable {
}
else
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
handleWebDriverAfterDownload
(
webDriver
);
}
WebDriver
.
Options
manage
=
webDriver
.
manage
();
...
...
webmagic-extension/src/main/java/us/codecraft/webmagic/downloader/WebDriverPool.java
View file @
6535928d
package
us
.
codecraft
.
webmagic
.
downloader
;
import
io.github.bonigarcia.wdm.*
;
import
org.apache.commons.lang3.SystemUtils
;
import
org.openqa.selenium.WebDriver
;
import
org.openqa.selenium.chrome.ChromeDriver
;
import
org.openqa.selenium.edge.EdgeDriver
;
...
...
@@ -11,9 +10,6 @@ import org.openqa.selenium.opera.OperaDriver;
import
org.openqa.selenium.phantomjs.PhantomJSDriver
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
us.codecraft.webmagic.Task
;
import
us.codecraft.webmagic.proxy.ProxyProvider
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
...
...
@@ -104,11 +100,12 @@ public class WebDriverPool {
*/
public
WebDriver
get
()
throws
InterruptedException
{
checkRunning
();
logger
.
info
(
"11现在的driver{}"
,
webDriverList
.
size
());
WebDriver
poll
=
innerQueue
.
poll
();
if
(
poll
!=
null
)
{
return
poll
;
}
logger
.
info
(
"现在的driver{}"
,
webDriverList
.
size
());
logger
.
info
(
"
22
现在的driver{}"
,
webDriverList
.
size
());
if
(
webDriverList
.
size
()
<
capacity
)
{
synchronized
(
webDriverList
)
{
if
(
webDriverList
.
size
()
<
capacity
)
{
...
...
webmagic-samples/pom.xml
View file @
6535928d
...
...
@@ -3,7 +3,7 @@
<parent>
<groupId>
us.codecraft.duiba
</groupId>
<artifactId>
webmagic-parent
</artifactId>
<version>
0.8.
0
-SNAPSHOT
</version>
<version>
0.8.
1
-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
webmagic-samples/src/main/java/us/codecraft/webmagic/samples/WeiboTopSpider.java
View file @
6535928d
...
...
@@ -51,29 +51,31 @@ public class WeiboTopSpider implements PageProcessor {
public
static
void
main
(
String
[]
args
)
throws
JMException
{
// SeleniumDownloader downloader = new SeleniumDownloader();
// downloader.setProxyProvider(new Data5UProxyProvider());
ProxyProvider
proxyProvider
=
SimpleProxyProvider
.
from
(
new
Proxy
(
"116.233.89.22"
,
8060
));
// downloader.setProxyProvider(SimpleProxyProvider.from(new Proxy("116.233.89.22",8060)));
ScheduledExecutorService
executorService
=
Executors
.
newSingleThreadScheduledExecutor
();
// Spider weiboSpider = Spider.create(new WeiboTopSpider())
//// .addUrl("http://s.weibo.com/top/summary").setDownloader(new SeleniumDownloader())
//// .addUrl("http://www.baidu.com","http://www.163.com","http://www.sina.com.cn/","http://www.qq.com/","http://www.iqiyi.com/").setDownloader(new SeleniumDownloader())
// .addUrl("http://www.sina.com.cn/").setDownloader(new SeleniumDownloader())
// .thread(1);
// weiboSpider.start();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
executorService
.
scheduleAtFixedRate
(
new
Runnable
()
{
@Override
public
void
run
()
{
SeleniumDownloader
seleniumDownloader
=
new
SeleniumDownloader
();
seleniumDownloader
.
setProxyProvider
(
proxyProvider
);
//
SeleniumDownloader seleniumDownloader = new SeleniumDownloader();
//
seleniumDownloader.setProxyProvider(proxyProvider);
Spider
weiboSpider
=
Spider
.
create
(
new
WeiboTopSpider
())
.
addUrl
(
"http://s.weibo.com/top/summary"
).
setDownloader
(
seleniumDownloader
)
.
addUrl
(
"http://s.weibo.com/top/summary"
).
setDownloader
(
new
SeleniumDownloader
())
// .addUrl("http://127.1.1.1:9090/").setDownloader(new SeleniumDownloader())
.
thread
(
1
);
weiboSpider
.
start
();
}
},
1
,
3
0
,
TimeUnit
.
SECONDS
);
},
1
,
6
0
,
TimeUnit
.
SECONDS
);
}
}
}
}
webmagic-saxon/pom.xml
View file @
6535928d
...
...
@@ -3,7 +3,7 @@
<parent>
<groupId>
us.codecraft.duiba
</groupId>
<artifactId>
webmagic-parent
</artifactId>
<version>
0.8.
0
-SNAPSHOT
</version>
<version>
0.8.
1
-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
webmagic-scripts/pom.xml
View file @
6535928d
...
...
@@ -3,7 +3,7 @@
<parent>
<groupId>
us.codecraft.duiba
</groupId>
<artifactId>
webmagic-parent
</artifactId>
<version>
0.8.
0
-SNAPSHOT
</version>
<version>
0.8.
1
-SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
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