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
ec77eca0
Commit
ec77eca0
authored
Mar 22, 2018
by
shenjunlin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码
parent
6448c69f
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
86 additions
and
26 deletions
+86
-26
pom.xml
pom.xml
+1
-1
pom.xml
webmagic-core/pom.xml
+1
-1
Page.java
webmagic-core/src/main/java/us/codecraft/webmagic/Page.java
+3
-0
ResultItems.java
...core/src/main/java/us/codecraft/webmagic/ResultItems.java
+4
-3
log4j.xml
webmagic-core/src/main/resources/log4j.xml
+4
-4
pom.xml
webmagic-extension/pom.xml
+16
-1
MySQLTool.java
.../src/main/java/us/codecraft/webmagic/utils/MySQLTool.java
+34
-0
log4j.xml
webmagic-extension/src/main/resources/log4j.xml
+4
-4
pom.xml
webmagic-samples/pom.xml
+1
-1
AnjukeSpider.java
...main/java/us/codecraft/webmagic/samples/AnjukeSpider.java
+16
-9
pom.xml
webmagic-saxon/pom.xml
+1
-1
pom.xml
webmagic-scripts/pom.xml
+1
-1
No files found.
pom.xml
View file @
ec77eca0
...
...
@@ -6,7 +6,7 @@
<version>
7
</version>
</parent>
<groupId>
us.codecraft.duiba
</groupId>
<version>
0.7.8-SNAPSHOT
</version>
<version>
0.7.8-
sjl-
SNAPSHOT
</version>
<modelVersion>
4.0.0
</modelVersion>
<packaging>
pom
</packaging>
<properties>
...
...
webmagic-core/pom.xml
View file @
ec77eca0
...
...
@@ -3,7 +3,7 @@
<parent>
<groupId>
us.codecraft.duiba
</groupId>
<artifactId>
webmagic-parent
</artifactId>
<version>
0.7.8-SNAPSHOT
</version>
<version>
0.7.8-
sjl-
SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
webmagic-core/src/main/java/us/codecraft/webmagic/Page.java
View file @
ec77eca0
...
...
@@ -266,4 +266,7 @@ public class Page {
", bytes="
+
Arrays
.
toString
(
bytes
)
+
'}'
;
}
public
void
addObjects
()
{
}
}
webmagic-core/src/main/java/us/codecraft/webmagic/ResultItems.java
View file @
ec77eca0
package
us
.
codecraft
.
webmagic
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.*
;
/**
* Object contains extract results.<br>
...
...
@@ -17,11 +15,14 @@ public class ResultItems {
private
Map
<
String
,
Object
>
fields
=
new
LinkedHashMap
<
String
,
Object
>();
private
List
<
Object
>
Objects
=
new
ArrayList
<>();
private
Request
request
;
private
boolean
skip
;
public
<
T
>
T
get
(
String
key
)
{
Object
o
=
fields
.
get
(
key
);
if
(
o
==
null
)
{
return
null
;
...
...
webmagic-core/src/main/resources/log4j.xml
View file @
ec77eca0
...
...
@@ -8,10 +8,10 @@
</layout>
</appender>
<
logger
name=
"org.apache"
additivity=
"false"
>
<
level
value=
"error"
/
>
<
appender-ref
ref=
"stdout"
/
>
<
/logger
>
<
!--<logger name="org.apache" additivity="false">--
>
<
!--<level value="error" />--
>
<
!--<appender-ref ref="stdout" />--
>
<
!--</logger>--
>
<root>
<level
value=
"info"
/>
...
...
webmagic-extension/pom.xml
View file @
ec77eca0
...
...
@@ -3,7 +3,7 @@
<parent>
<groupId>
us.codecraft.duiba
</groupId>
<artifactId>
webmagic-parent
</artifactId>
<version>
0.7.8-SNAPSHOT
</version>
<version>
0.7.8-
sjl-
SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
@@ -56,6 +56,21 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
5.1.6
</version>
</dependency>
<dependency>
<groupId>
commons-dbutils
</groupId>
<artifactId>
commons-dbutils
</artifactId>
<version>
1.7
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
druid
</artifactId>
<version>
1.1.6
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
webmagic-extension/src/main/java/us/codecraft/webmagic/utils/MySQLTool.java
0 → 100644
View file @
ec77eca0
package
us
.
codecraft
.
webmagic
.
utils
;
import
com.alibaba.druid.pool.DruidDataSource
;
import
org.apache.commons.dbutils.QueryRunner
;
import
java.sql.SQLException
;
public
class
MySQLTool
{
private
DruidDataSource
dataSource
;
private
QueryRunner
queryRunner
;
private
String
insertSql
;
public
MySQLTool
setInsertSql
(
String
insertSql
){
this
.
insertSql
=
insertSql
;
return
this
;
}
public
MySQLTool
(
String
url
,
String
userName
,
String
password
){
dataSource
=
new
DruidDataSource
();
dataSource
.
setDriverClassName
(
"com.mysql.jdbc.Driver"
);
dataSource
.
setUrl
(
url
);
dataSource
.
setUsername
(
userName
);
dataSource
.
setPassword
(
password
);
queryRunner
=
new
QueryRunner
(
dataSource
);
}
public
void
insert
(
Object
...
params
)
throws
SQLException
{
queryRunner
.
update
(
insertSql
,
params
);
}
}
webmagic-extension/src/main/resources/log4j.xml
View file @
ec77eca0
...
...
@@ -8,10 +8,10 @@
</layout>
</appender>
<
logger
name=
"org.apache"
additivity=
"false"
>
<
level
value=
"error"
/
>
<
appender-ref
ref=
"stdout"
/
>
<
/logger
>
<
!--<logger name="org.apache" additivity="false">--
>
<
!--<level value="error" />--
>
<
!--<appender-ref ref="stdout" />--
>
<
!--</logger>--
>
<root>
<level
value=
"info"
/>
...
...
webmagic-samples/pom.xml
View file @
ec77eca0
...
...
@@ -3,7 +3,7 @@
<parent>
<groupId>
us.codecraft.duiba
</groupId>
<artifactId>
webmagic-parent
</artifactId>
<version>
0.7.8-SNAPSHOT
</version>
<version>
0.7.8-
sjl-
SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
webmagic-samples/src/main/java/us/codecraft/webmagic/samples/AnjukeSpider.java
View file @
ec77eca0
...
...
@@ -8,6 +8,7 @@ import us.codecraft.webmagic.Site;
import
us.codecraft.webmagic.Spider
;
import
us.codecraft.webmagic.downloader.HttpClientDownloader
;
import
us.codecraft.webmagic.model.samples.AnjuKeVO
;
import
us.codecraft.webmagic.pipeline.ConsolePipeline
;
import
us.codecraft.webmagic.processor.PageProcessor
;
import
us.codecraft.webmagic.scheduler.FileCacheQueueScheduler
;
import
us.codecraft.webmagic.scheduler.component.HashSetDuplicateRemover
;
...
...
@@ -53,14 +54,20 @@ public class AnjukeSpider implements PageProcessor {
String
area
=
StringUtils
.
substringBetween
(
areaAddress
,
"["
,
"]"
).
trim
();
String
address
=
StringUtils
.
substringAfter
(
areaAddress
,
"]"
).
trim
();
String
price
=
selectable
.
$
(
".li-side > p > strong"
,
"text"
).
get
().
trim
();
AnjuKeVO
anjuKeVO
=
new
AnjuKeVO
();
anjuKeVO
.
setAddress
(
address
);
anjuKeVO
.
setArea
(
area
);
anjuKeVO
.
setCity
(
city
);
anjuKeVO
.
setPrice
(
price
);
anjuKeVO
.
setCommunityName
(
communityName
);
anjuKeVO
.
setUrl
(
page
.
getRequest
().
getUrl
());
DBUtils
.
add
(
anjuKeVO
);
page
.
putField
(
"communityName"
,
communityName
);
page
.
putField
(
"areaAddress"
,
areaAddress
);
page
.
putField
(
"address"
,
address
);
page
.
putField
(
"area"
,
area
);
page
.
putField
(
"price"
,
price
);
page
.
addObjects
();
// AnjuKeVO anjuKeVO = new AnjuKeVO();
// anjuKeVO.setAddress(address);
// anjuKeVO.setArea(area);
// anjuKeVO.setCity(city);
// anjuKeVO.setPrice(price);
// anjuKeVO.setCommunityName(communityName);
// anjuKeVO.setUrl(page.getRequest().getUrl());
// DBUtils.add(anjuKeVO);
}
page
.
addTargetRequests
(
page
.
getHtml
().
$
(
".page-content"
).
links
().
all
());
}
...
...
@@ -78,7 +85,7 @@ public class AnjukeSpider implements PageProcessor {
.
setScheduler
(
new
FileCacheQueueScheduler
(
"spider"
).
setDuplicateRemover
(
new
HashSetDuplicateRemover
()))
.
addUrl
(
"https://www.anjuke.com/sy-city.html"
)
// .addUrl("https://lvliang.anjuke.com/community/p1/")
.
thread
(
2
);
.
thread
(
2
)
.
addPipeline
(
new
ConsolePipeline
())
;
anjuke
.
start
();
}
...
...
webmagic-saxon/pom.xml
View file @
ec77eca0
...
...
@@ -3,7 +3,7 @@
<parent>
<groupId>
us.codecraft.duiba
</groupId>
<artifactId>
webmagic-parent
</artifactId>
<version>
0.7.8-SNAPSHOT
</version>
<version>
0.7.8-
sjl-
SNAPSHOT
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
webmagic-scripts/pom.xml
View file @
ec77eca0
...
...
@@ -3,7 +3,7 @@
<parent>
<groupId>
us.codecraft.duiba
</groupId>
<artifactId>
webmagic-parent
</artifactId>
<version>
0.7.8-SNAPSHOT
</version>
<version>
0.7.8-
sjl-
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