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
3939074a
Commit
3939074a
authored
May 27, 2014
by
yihua.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bugfix: nodes() only return the first element #113
parent
41c2ea94
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
HtmlNode.java
...rc/main/java/us/codecraft/webmagic/selector/HtmlNode.java
+6
-2
SelectorTest.java
...est/java/us/codecraft/webmagic/selector/SelectorTest.java
+9
-0
No files found.
webmagic-core/src/main/java/us/codecraft/webmagic/selector/HtmlNode.java
View file @
3939074a
...
@@ -81,8 +81,12 @@ public class HtmlNode extends AbstractSelectable {
...
@@ -81,8 +81,12 @@ public class HtmlNode extends AbstractSelectable {
@Override
@Override
public
List
<
Selectable
>
nodes
()
{
public
List
<
Selectable
>
nodes
()
{
ArrayList
<
Selectable
>
selectables
=
new
ArrayList
<
Selectable
>();
List
<
Selectable
>
selectables
=
new
ArrayList
<
Selectable
>();
selectables
.
add
(
this
);
for
(
Element
element
:
getElements
())
{
List
<
Element
>
childElements
=
new
ArrayList
<
Element
>(
1
);
childElements
.
add
(
element
);
selectables
.
add
(
new
HtmlNode
(
childElements
));
}
return
selectables
;
return
selectables
;
}
}
...
...
webmagic-core/src/test/java/us/codecraft/webmagic/selector/SelectorTest.java
View file @
3939074a
...
@@ -23,4 +23,13 @@ public class SelectorTest {
...
@@ -23,4 +23,13 @@ public class SelectorTest {
assertThat
(
linksWithoutChain
).
hasSameSizeAs
(
linksWithChainFirstCall
);
assertThat
(
linksWithoutChain
).
hasSameSizeAs
(
linksWithChainFirstCall
);
assertThat
(
linksWithChainFirstCall
).
hasSameSizeAs
(
linksWithChainSecondCall
);
assertThat
(
linksWithChainFirstCall
).
hasSameSizeAs
(
linksWithChainSecondCall
);
}
}
@Test
public
void
testNodes
()
throws
Exception
{
Html
selectable
=
new
Html
(
html
);
List
<
Selectable
>
links
=
selectable
.
xpath
(
"//a"
).
nodes
();
for
(
Selectable
link
:
links
)
{
System
.
out
.
println
(
link
.
xpath
(
"/@href"
));
}
}
}
}
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