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
521fbad9
Commit
521fbad9
authored
Aug 07, 2013
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move xpath2.0 support to seperate package
parent
268bd8d0
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
50 additions
and
48 deletions
+50
-48
pom.xml
pom.xml
+1
-0
pom.xml
webmagic-extension/pom.xml
+0
-4
PageModelExtractor.java
.../java/us/codecraft/webmagic/model/PageModelExtractor.java
+7
-19
ExtractBy.java
...ava/us/codecraft/webmagic/model/annotation/ExtractBy.java
+2
-2
ExtractBy2.java
...va/us/codecraft/webmagic/model/annotation/ExtractBy2.java
+3
-2
ExtractBy3.java
...va/us/codecraft/webmagic/model/annotation/ExtractBy3.java
+2
-2
ExtractByRaw.java
.../us/codecraft/webmagic/model/annotation/ExtractByRaw.java
+2
-2
README.md
webmagic-saxon/README.md
+3
-0
pom.xml
webmagic-saxon/pom.xml
+30
-0
Xpath2Selector.java
...n/java/us/codecraft/webmagic/selector/Xpath2Selector.java
+0
-0
XpathSelectorTest.java
...ava/us/codecraft/webmagic/selector/XpathSelectorTest.java
+0
-17
No files found.
pom.xml
View file @
521fbad9
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
<module>
webmagic-samples/
</module>
<module>
webmagic-samples/
</module>
<module>
webmagic-selenium/
</module>
<module>
webmagic-selenium/
</module>
<module>
webmagic-lucene/
</module>
<module>
webmagic-lucene/
</module>
<module>
webmagic-saxon/
</module>
</modules>
</modules>
<dependencyManagement>
<dependencyManagement>
...
...
webmagic-extension/pom.xml
View file @
521fbad9
...
@@ -27,10 +27,6 @@
...
@@ -27,10 +27,6 @@
<artifactId>
webmagic-core
</artifactId>
<artifactId>
webmagic-core
</artifactId>
<version>
${project.version}
</version>
<version>
${project.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
net.sf.saxon
</groupId>
<artifactId>
Saxon-HE
</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>
junit
</groupId>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<artifactId>
junit
</artifactId>
...
...
webmagic-extension/src/main/java/us/codecraft/webmagic/model/PageModelExtractor.java
View file @
521fbad9
...
@@ -110,11 +110,8 @@ class PageModelExtractor {
...
@@ -110,11 +110,8 @@ class PageModelExtractor {
case
XPath:
case
XPath:
selector
=
new
XpathSelector
(
value
);
selector
=
new
XpathSelector
(
value
);
break
;
break
;
case
XPath2:
selector
=
new
Xpath2Selector
(
value
);
break
;
default
:
default
:
selector
=
new
Xpath
2
Selector
(
value
);
selector
=
new
XpathSelector
(
value
);
}
}
fieldExtractor
=
new
FieldExtractor
(
field
,
selector
,
FieldExtractor
.
Source
.
Html
,
extractBy
.
notNull
(),
extractBy
.
multi
());
fieldExtractor
=
new
FieldExtractor
(
field
,
selector
,
FieldExtractor
.
Source
.
Html
,
extractBy
.
notNull
(),
extractBy
.
multi
());
Method
setterMethod
=
getSetterMethod
(
clazz
,
field
);
Method
setterMethod
=
getSetterMethod
(
clazz
,
field
);
...
@@ -140,11 +137,8 @@ class PageModelExtractor {
...
@@ -140,11 +137,8 @@ class PageModelExtractor {
case
XPath:
case
XPath:
selector
=
new
XpathSelector
(
value
);
selector
=
new
XpathSelector
(
value
);
break
;
break
;
case
XPath2:
selector
=
new
Xpath2Selector
(
value
);
break
;
default
:
default
:
selector
=
new
Xpath
2
Selector
(
value
);
selector
=
new
XpathSelector
(
value
);
}
}
fieldExtractor
.
setSelector
(
new
AndSelector
(
fieldExtractor
.
getSelector
(),
selector
));
fieldExtractor
.
setSelector
(
new
AndSelector
(
fieldExtractor
.
getSelector
(),
selector
));
}
}
...
@@ -165,11 +159,8 @@ class PageModelExtractor {
...
@@ -165,11 +159,8 @@ class PageModelExtractor {
case
XPath:
case
XPath:
selector
=
new
XpathSelector
(
value
);
selector
=
new
XpathSelector
(
value
);
break
;
break
;
case
XPath2:
selector
=
new
Xpath2Selector
(
value
);
break
;
default
:
default
:
selector
=
new
Xpath
2
Selector
(
value
);
selector
=
new
XpathSelector
(
value
);
}
}
fieldExtractor
.
setSelector
(
new
AndSelector
(
fieldExtractor
.
getSelector
(),
selector
));
fieldExtractor
.
setSelector
(
new
AndSelector
(
fieldExtractor
.
getSelector
(),
selector
));
}
}
...
@@ -191,11 +182,8 @@ class PageModelExtractor {
...
@@ -191,11 +182,8 @@ class PageModelExtractor {
case
XPath:
case
XPath:
selector
=
new
XpathSelector
(
value
);
selector
=
new
XpathSelector
(
value
);
break
;
break
;
case
XPath2:
selector
=
new
Xpath2Selector
(
value
);
break
;
default
:
default
:
selector
=
new
Xpath
2
Selector
(
value
);
selector
=
new
XpathSelector
(
value
);
}
}
fieldExtractor
=
new
FieldExtractor
(
field
,
selector
,
FieldExtractor
.
Source
.
RawHtml
,
extractByRaw
.
notNull
(),
extractByRaw
.
multi
());
fieldExtractor
=
new
FieldExtractor
(
field
,
selector
,
FieldExtractor
.
Source
.
RawHtml
,
extractByRaw
.
notNull
(),
extractByRaw
.
multi
());
Method
setterMethod
=
getSetterMethod
(
clazz
,
field
);
Method
setterMethod
=
getSetterMethod
(
clazz
,
field
);
...
@@ -228,7 +216,7 @@ class PageModelExtractor {
...
@@ -228,7 +216,7 @@ class PageModelExtractor {
targetUrlPatterns
.
add
(
Pattern
.
compile
(
"("
+
s
.
replace
(
"."
,
"\\."
).
replace
(
"*"
,
"[^\"'#]*"
)
+
")"
));
targetUrlPatterns
.
add
(
Pattern
.
compile
(
"("
+
s
.
replace
(
"."
,
"\\."
).
replace
(
"*"
,
"[^\"'#]*"
)
+
")"
));
}
}
if
(!
targetUrl
.
sourceRegion
().
equals
(
""
))
{
if
(!
targetUrl
.
sourceRegion
().
equals
(
""
))
{
targetUrlRegionSelector
=
new
Xpath
2
Selector
(
targetUrl
.
sourceRegion
());
targetUrlRegionSelector
=
new
XpathSelector
(
targetUrl
.
sourceRegion
());
}
}
}
}
annotation
=
clazz
.
getAnnotation
(
HelpUrl
.
class
);
annotation
=
clazz
.
getAnnotation
(
HelpUrl
.
class
);
...
@@ -239,13 +227,13 @@ class PageModelExtractor {
...
@@ -239,13 +227,13 @@ class PageModelExtractor {
helpUrlPatterns
.
add
(
Pattern
.
compile
(
"("
+
s
.
replace
(
"."
,
"\\."
).
replace
(
"*"
,
"[^\"'#]*"
)
+
")"
));
helpUrlPatterns
.
add
(
Pattern
.
compile
(
"("
+
s
.
replace
(
"."
,
"\\."
).
replace
(
"*"
,
"[^\"'#]*"
)
+
")"
));
}
}
if
(!
helpUrl
.
sourceRegion
().
equals
(
""
))
{
if
(!
helpUrl
.
sourceRegion
().
equals
(
""
))
{
helpUrlRegionSelector
=
new
Xpath
2
Selector
(
helpUrl
.
sourceRegion
());
helpUrlRegionSelector
=
new
XpathSelector
(
helpUrl
.
sourceRegion
());
}
}
}
}
annotation
=
clazz
.
getAnnotation
(
ExtractBy
.
class
);
annotation
=
clazz
.
getAnnotation
(
ExtractBy
.
class
);
if
(
annotation
!=
null
)
{
if
(
annotation
!=
null
)
{
ExtractBy
extractBy
=
(
ExtractBy
)
annotation
;
ExtractBy
extractBy
=
(
ExtractBy
)
annotation
;
extractor
=
new
Extractor
(
new
Xpath
2
Selector
(
extractBy
.
value
()),
Extractor
.
Source
.
Html
,
extractBy
.
notNull
(),
extractBy
.
multi
());
extractor
=
new
Extractor
(
new
XpathSelector
(
extractBy
.
value
()),
Extractor
.
Source
.
Html
,
extractBy
.
notNull
(),
extractBy
.
multi
());
}
}
}
}
...
...
webmagic-extension/src/main/java/us/codecraft/webmagic/model/annotation/ExtractBy.java
View file @
521fbad9
...
@@ -16,9 +16,9 @@ public @interface ExtractBy {
...
@@ -16,9 +16,9 @@ public @interface ExtractBy {
String
value
();
String
value
();
public
enum
Type
{
XPath
2
,
XPath
,
Regex
,
Css
}
public
enum
Type
{
XPath
,
Regex
,
Css
}
Type
type
()
default
Type
.
XPath
2
;
Type
type
()
default
Type
.
XPath
;
boolean
notNull
()
default
true
;
boolean
notNull
()
default
true
;
...
...
webmagic-extension/src/main/java/us/codecraft/webmagic/model/annotation/ExtractBy2.java
View file @
521fbad9
...
@@ -6,6 +6,7 @@ import java.lang.annotation.Target;
...
@@ -6,6 +6,7 @@ import java.lang.annotation.Target;
/**
/**
* 定义类或者字段的抽取规则。<br>
* 定义类或者字段的抽取规则。<br>
*
* @author code4crafter@gmail.com <br>
* @author code4crafter@gmail.com <br>
* @date: 13-8-1 <br>
* @date: 13-8-1 <br>
* Time: 下午8:40 <br>
* Time: 下午8:40 <br>
...
@@ -16,8 +17,8 @@ public @interface ExtractBy2 {
...
@@ -16,8 +17,8 @@ public @interface ExtractBy2 {
String
value
();
String
value
();
public
enum
Type
{
XPath
2
,
XPath
,
Regex
,
Css
}
public
enum
Type
{
XPath
,
Regex
,
Css
}
Type
type
()
default
Type
.
XPath
2
;
Type
type
()
default
Type
.
XPath
;
}
}
webmagic-extension/src/main/java/us/codecraft/webmagic/model/annotation/ExtractBy3.java
View file @
521fbad9
...
@@ -16,8 +16,8 @@ public @interface ExtractBy3 {
...
@@ -16,8 +16,8 @@ public @interface ExtractBy3 {
String
value
();
String
value
();
public
enum
Type
{
XPath2
,
XPath
,
Regex
,
Css
}
public
enum
Type
{
XPath
,
Regex
,
Css
}
Type
type
()
default
Type
.
XPath
2
;
Type
type
()
default
Type
.
XPath
;
}
}
webmagic-extension/src/main/java/us/codecraft/webmagic/model/annotation/ExtractByRaw.java
View file @
521fbad9
...
@@ -16,9 +16,9 @@ public @interface ExtractByRaw {
...
@@ -16,9 +16,9 @@ public @interface ExtractByRaw {
String
value
();
String
value
();
public
enum
Type
{
XPath
2
,
XPath
,
Regex
,
Css
}
public
enum
Type
{
XPath
,
Regex
,
Css
}
Type
type
()
default
Type
.
XPath
2
;
Type
type
()
default
Type
.
XPath
;
boolean
notNull
()
default
true
;
boolean
notNull
()
default
true
;
...
...
webmagic-saxon/README.md
0 → 100644
View file @
521fbad9
webmagic-extension
-------
webmagic的扩展模块,依赖Saxon进行xpath2.0解析支持。Saxon依赖包太大,不作为默认模块引入。
\ No newline at end of file
webmagic-saxon/pom.xml
0 → 100644
View file @
521fbad9
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<groupId>
us.codecraft
</groupId>
<artifactId>
webmagic
</artifactId>
<version>
0.2.0
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
webmagic-saxon
</artifactId>
<dependencies>
<dependency>
<groupId>
us.codecraft
</groupId>
<artifactId>
webmagic-core
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
net.sf.saxon
</groupId>
<artifactId>
Saxon-HE
</artifactId>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
webmagic-
extensi
on/src/main/java/us/codecraft/webmagic/selector/Xpath2Selector.java
→
webmagic-
sax
on/src/main/java/us/codecraft/webmagic/selector/Xpath2Selector.java
View file @
521fbad9
File moved
webmagic-
extensi
on/src/test/java/us/codecraft/webmagic/selector/XpathSelectorTest.java
→
webmagic-
sax
on/src/test/java/us/codecraft/webmagic/selector/XpathSelectorTest.java
View file @
521fbad9
package
us
.
codecraft
.
webmagic
.
selector
;
package
us
.
codecraft
.
webmagic
.
selector
;
import
net.sf.saxon.Configuration
;
import
net.sf.saxon.lib.NamespaceConstant
;
import
net.sf.saxon.om.NamespaceResolver
;
import
net.sf.saxon.pull.NamespaceContextImpl
;
import
net.sf.saxon.xpath.JAXPXPathStaticContext
;
import
net.sf.saxon.xpath.XPathEvaluator
;
import
net.sf.saxon.xpath.XPathFactoryImpl
;
import
org.htmlcleaner.CleanerProperties
;
import
org.htmlcleaner.DomSerializer
;
import
org.htmlcleaner.HtmlCleaner
;
import
org.htmlcleaner.TagNode
;
import
org.junit.Assert
;
import
org.junit.Assert
;
import
org.junit.Ignore
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.NodeList
;
import
javax.xml.xpath.*
;
import
java.util.Collections
;
import
java.util.Iterator
;
/**
/**
* @author code4crafter@gmail.com <br> Date: 13-4-21 Time: 上午10:06
* @author code4crafter@gmail.com <br> Date: 13-4-21 Time: 上午10:06
...
...
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