我正在尝试解析网页中给定标题下的所有内容。 (这不应包括下一个标题下的数据)。
我尝试了以下内容:
- >选择(不知何故)所需的标题(带孩子)。
- >删除下一个标题(我们只需要当前标题。
第二步的代码:
//prune out next headings (we only need current heading
for( int tempIndex = 1; tempIndex < theseMayContainLinks.size(); tempIndex++ ){//start from next element
if(theseMayContainLinks.get(tempIndex).toString().contains(currentElement.tagName())){
for(int removeIndex = tempIndex; removeIndex < theseMayContainLinks.size(); removeIndex++){
theseMayContainLinks.remove(removeIndex);
}
}
}
我已在this question中读到remove()
将从Document
删除,而不是Elements
。 您能否建议如何从Elements
中删除。
theseMayContainLinks
包含以下33个Element
:
<div style="margin-left: 40px;">
Match an animated motion to a verbal description or a graphical description in the Name That Motion and Graph That Motion Interactives. Build a ramp along which a ball will roll in order for its motion to match a given graph with the Graph and Ramps Interactive.
Combine the Accelerometer Interactive with the acceleration sensors on your mobile devices to measure the acceleration of your device. Learn how displacement and distance are different in the Vector Walk Interactive.
<br>
<br>Visit
<a href="/Physics-Interactives/Kinematics">1-D Kinematics Interactives</a>.
<br>
</div>
<h3>Newton's Laws of Motion</h3>
<div style="margin-left: 40px;">
Explore relationships pertaining to applied force, friction force, mass, and acceleration with the Force Interactive. Practice your skill of constructing free-body diagrams with the Free Body Diagram Interactive. Learn about Newton's second law of motion
with the Rocket Sled and Skydiving Interactives. Find out why you feel weightless and weighty with the Elevator Ride Interactive.
<br>
<br>Visit
<a href="/Physics-Interactives/Newtons-Laws">Newton's Laws Interactives</a>.
<br>
</div>
<h3>Vectors, Projectiles and Two-Dimensional Motion</h3>
<div style="margin-left: 40px;">
Learn important rules about adding vectors with the Vector Addition Interactive. Practice adding vectors by adding their components with the Name That Vectors Interactive. Be smart ... be fast ,,, and challenge your friends at the Vector Guessing Game.
Use the Projectile Simulator to uncover some fundamental principles pertaining to motion in two dimensions. And explore an age-old question with the Monkey and Zookeeper Interactive.
<br>
<br>Visit
<a href="/Physics-Interactives/Vectors-and-Projectiles">Vectors, Projectiles, and 2-D Motion Interactives</a>.
<br>
</div>
<h3>Momentum and Collisions</h3>
<div style="margin-left: 40px;">
Conduct an Egg Drop study and learn about factors affecting the collision force. Investigate collisions with the Cart and Brick Interactive. Study momentum conservation with the Fish Catch and Exploding Carts Interactives. Explore collision and explosion
principles like never before with the Colliding Carts Interactive.
<br>
<br>Visit
<a href="/Physics-Interactives/Momentum-and-Collisions">Momentum and Collisions Interactives</a>.
<br>
</div>
<h3>Work and Energy</h3>
<div style="margin-left: 40px;">
Investigate force and work with the It's All Uphill Interactive. Learn how speed affects stopping distance with the Stopping Distance Interactive. Build a coaster or use a pre-built coaster to explore the physics of roller coasters with the Roller Coaster
Model. Practice your skill with work-energy bar charts using the Chart That Motion Interactive.
<br>
<br>Visit
<a href="/Physics-Interactives/Work-and-Energy">Work and Energy Interactives</a>.
<br>
</div>
<h3>Circular Motion and Gravitation</h3>
<div style="margin-left: 40px;">
Explore uniform circular motion principles with the Circular Motion Interactive. Apply a force to a car to race it around an oval race track; compete with friends to finish the race in the least number of moves with the Race Track Interactive. Explore
the forces acting on a roller coaster car with the Roller Coaster Model Interactive. Learn about the variables that affect the thrill and safety of a roller coaster ride with the Roller Coaster Design Interactive. Learn about weightlessness and
weightiness with the Elevator Ride Interactive. Study Kepler's laws with the Orbital Motion Interactive. Launch the Gravitation Interactive and discover the universal law of gravitation. Explore universal gravitation, gravitational field strength, the
value of g, and your weight on other planets with our many other
<em>out-of-this-world</em> Interactives.
<br>
<br>Visit
<a href="/Physics-Interactives/Circular-and-Satellite-Motion">Circular and Satellite Motion Interactives</a>.
<br>
</div>
<h3>Balance and Rotation</h3>
<div style="margin-left: 40px;">
Set a couple of bugs on a rotating platform and spin them around while you learn about the relationship between linear and rotational velocity using our Rotational Motion Simulation. Construct an object with a given shape and hang it from a push pin on
a corkboard in our Center of Mass Simulation.
<br>
<br>Visit
<a href="/Physics-Interactives/Balance-and-Rotation">Rotation and Balance Interactives</a>.
<br>
</div>
<h3>Static Electricity</h3>
<div style="margin-left: 40px;">
Learn about the law that governs the force acting between charged objects with the Coulomb's Law Interactive. Explore charging methods with the Charging simulation or the Name That Charge skill-builder activity. Explore the complex set of electric field
lines that surround a single charge or a configuration of charges with the Electric Field Interactive. Use charge interactions and field forces to guide a
<em>charged</em>
<em>puck</em> into the goal in the Put the Charge in the Goal Interactive.
<br>
<br>Visit
<a href="/Physics-Interactives/Static-Electricity">Static Electricity Interactives</a>.
<br>
</div>
<h3>Electric Circuits</h3>
<div style="margin-left: 40px;">
Build a circuit. Add a resistor or a light bulb and a meter to measure current or voltage drops. Tap/click a battery or resistor to change its voltage or resistance. Build single-resistor circuit and study the voltage-current-resistance relationship.
Or build a series, parallel or combination circuit and explore how they work. Study just about anything and everything pertaining to electric circuits with the DC Circuit Builder Interactive.
<br>
<br>Visit
<a href="/Physics-Interactives/Electric-Circuits">Electric Circuits Interactives</a>.
<br>
</div>
<h3>Magnetism</h3>
<div style="margin-left: 40px;">
Observe the interaction between a bar magnet and the needle of a compass with our Magnetic Field Simulator.
<br>
<br>Visit
<a href="/Physics-Interactives/Magnetism">Magnetism Interactives</a>.
<br>
</div>
<h3>Waves and Sound</h3>
<div style="margin-left: 40px;">
Explore the nature of a wave and the relationship between waves and sound with the Simple Wave Simulator. Study the motion of waves on a string and the effect of tension, density and damping upon their behavior with the Slinky Lab Interactive. Create
standing waves and investigate their patterns with the Standing Wave Maker Interactive.
<br>
<br>Visit
<a href="/Physics-Interactives/Waves-and-Sound">Waves and Sound Interactives</a>
<br>
</div>
<h3>Reflection and Mirrors</h3>
<div style="margin-left: 40px;">
<span style="font-size: 12px;">Study plane mirror images with the Who Can See Who? Interactive. Use the Optics Bench Interactive to explore the images formed by concave and convex mirrors. Practice your skill at recognize the characteristics of curved mirror images with the Name That Image Interactive.</span>
</div>
<div style="margin-left: 40px;">
<br>Visit
<a href="/Physics-Interactives/Reflection-and-Mirrors">Reflection and Mirrors Interactives</a>.
<br>
</div>
<h3>Refraction and Lenses</h3>
<div style="margin-left: 40px;">
Explore the refraction of light at a boundary between two media with the Refraction Interactive. Launch the Least Time Principle Interactive and discover the fundamental law that explains why light refracts as it does when traveling between two locations
on the opposite side of a boundary. Use the Optics Bench Interactive to explore the images formed by converging and diverging lenses.
<br>
<br>Visit
<a href="/Physics-Interactives/Refraction-and-Lenses">Refraction and Lenses Interactives</a>.
</div>
<h3> </h3>
&#13;
currentElement
包含标题。例如:
// <h3>1-Dimensional Kinematics</h3>
(不是//:P)
我只想选择:
(基本上是下一个标题之前的所有内容;这可能包括多个div)
<div style="margin-left: 40px;">
Match an animated motion to a verbal description or a graphical description in the Name That Motion and Graph That Motion Interactives. Build a ramp along which a ball will roll in order for its motion to match a given graph with the Graph and Ramps Interactive.
Combine the Accelerometer Interactive with the acceleration sensors on your mobile devices to measure the acceleration of your device. Learn how displacement and distance are different in the Vector Walk Interactive.
<br>
<br>Visit
<a href="/Physics-Interactives/Kinematics">1-D Kinematics Interactives</a>.
<br>
</div>
&#13;
如果还有其他办法可以做我想做的事情,请提出建议。
感谢您的时间。
供您参考,这是我所谈论的网页(的一部分):
<div class="pane span9" id="contentHolder">
<div class="breadcrumbs"><a href="/">The Physics Classroom</a> »
<span class="ReadWatchInteract">Physics Interactives</span>
</div>
<h1>Physics Interactives</h1>Welcome to Physics Interactives! This section of our website features a collection of HTML5 interactive pages that allow a user to explore a physics concept. Some Interactives are simulations that allow a user to manipulate an environment and observe
the effect of changes in variables upon the simulation. Other Interactives are skill building exercises in which a user practices a skill that is crucial to learning some aspect of physics. And still other Interactives provide game-like environments
that require the user to use a physics concept to meet a challenge. The Interactives are intended to be used by the individual student or learner who is attempting to further understand the concept or by a teacher-led classroom as part of a lesson or
homework assignment. Most of the Interactives are accompanied by an activity sheet that suggests ways to use the Interactive. Learn more <a href="/Physics-Interactives/About-the-Physics-Interactives">About the Physics Interactives</a>.
<br>
<br>
<br>Interactives are organized by topic. Click a topic below to view interactives for that topic.
<h3 style="color:red;"><strong>Topics:</strong></h3>
<h3>1-Dimensional Kinematics</h3>
<div style="margin-left: 40px;">Match an animated motion to a verbal description or a graphical description in the Name That Motion and Graph That Motion Interactives. Build a ramp along which a ball will roll in order for its motion to match a given graph with the Graph and Ramps
Interactive. Combine the Accelerometer Interactive with the acceleration sensors on your mobile devices to measure the acceleration of your device. Learn how displacement and distance are different in the Vector Walk Interactive.
<br>
<br>Visit <a href="/Physics-Interactives/Kinematics">1-D Kinematics Interactives</a>.
<br>
</div>
<h3>Newton's Laws of Motion</h3>
<div style="margin-left: 40px;">Explore relationships pertaining to applied force, friction force, mass, and acceleration with the Force Interactive. Practice your skill of constructing free-body diagrams with the Free Body Diagram Interactive. Learn about Newton's second law of motion
with the Rocket Sled and Skydiving Interactives. Find out why you feel weightless and weighty with the Elevator Ride Interactive.
<br>
<br>Visit <a href="/Physics-Interactives/Newtons-Laws">Newton's Laws Interactives</a>.
<br>
</div>
<h3>Vectors, Projectiles and Two-Dimensional Motion</h3>
<div style="margin-left: 40px;">Learn important rules about adding vectors with the Vector Addition Interactive. Practice adding vectors by adding their components with the Name That Vectors Interactive. Be smart ... be fast ,,, and challenge your friends at the Vector Guessing Game.
Use the Projectile Simulator to uncover some fundamental principles pertaining to motion in two dimensions. And explore an age-old question with the Monkey and Zookeeper Interactive.
<br>
<br>Visit <a href="/Physics-Interactives/Vectors-and-Projectiles">Vectors, Projectiles, and 2-D Motion Interactives</a>.
<br>
</div>
<h3>Momentum and Collisions</h3>
<div style="margin-left: 40px;">Conduct an Egg Drop study and learn about factors affecting the collision force. Investigate collisions with the Cart and Brick Interactive. Study momentum conservation with the Fish Catch and Exploding Carts Interactives. Explore collision and explosion
principles like never before with the Colliding Carts Interactive.
<br>
<br>Visit <a href="/Physics-Interactives/Momentum-and-Collisions">Momentum and Collisions Interactives</a>.
<br>
</div>
<h3>Work and Energy</h3>
<div style="margin-left: 40px;">Investigate force and work with the It's All Uphill Interactive. Learn how speed affects stopping distance with the Stopping Distance Interactive. Build a coaster or use a pre-built coaster to explore the physics of roller coasters with the Roller Coaster
Model. Practice your skill with work-energy bar charts using the Chart That Motion Interactive.
<br>
<br>Visit <a href="/Physics-Interactives/Work-and-Energy">Work and Energy Interactives</a>.
<br>
</div>
<h3>Circular Motion and Gravitation</h3>
<div style="margin-left: 40px;">Explore uniform circular motion principles with the Circular Motion Interactive. Apply a force to a car to race it around an oval race track; compete with friends to finish the race in the least number of moves with the Race Track Interactive. Explore
the forces acting on a roller coaster car with the Roller Coaster Model Interactive. Learn about the variables that affect the thrill and safety of a roller coaster ride with the Roller Coaster Design Interactive. Learn about weightlessness and
weightiness with the Elevator Ride Interactive. Study Kepler's laws with the Orbital Motion Interactive. Launch the Gravitation Interactive and discover the universal law of gravitation. Explore universal gravitation, gravitational field strength,
the value of g, and your weight on other planets with our many other <em>out-of-this-world</em> Interactives.
<br>
<br>Visit <a href="/Physics-Interactives/Circular-and-Satellite-Motion">Circular and Satellite Motion Interactives</a>.
<br>
</div>
<h3>Balance and Rotation</h3>
<div style="margin-left: 40px;">Set a couple of bugs on a rotating platform and spin them around while you learn about the relationship between linear and rotational velocity using our Rotational Motion Simulation. Construct an object with a given shape and hang it from a push pin
on a corkboard in our Center of Mass Simulation.
<br>
<br>Visit
<a href="/Physics-Interactives/Balance-and-Rotation">Rotation and Balance Interactives</a>.
<br>
</div>
<h3>Static Electricity</h3>
<div style="margin-left: 40px;">Learn about the law that governs the force acting between charged objects with the Coulomb's Law Interactive. Explore charging methods with the Charging simulation or the Name That Charge skill-builder activity. Explore the complex set of electric field
lines that surround a single charge or a configuration of charges with the Electric Field Interactive. Use charge interactions and field forces to guide a <em>charged</em> <em>puck</em> into the goal in the Put the Charge in the Goal Interactive.
<br>
<br>Visit <a href="/Physics-Interactives/Static-Electricity">Static Electricity Interactives</a>.
<br>
</div>
<h3>Electric Circuits</h3>
<div style="margin-left: 40px;">Build a circuit. Add a resistor or a light bulb and a meter to measure current or voltage drops. Tap/click a battery or resistor to change its voltage or resistance. Build single-resistor circuit and study the voltage-current-resistance relationship.
Or build a series, parallel or combination circuit and explore how they work. Study just about anything and everything pertaining to electric circuits with the DC Circuit Builder Interactive.
<br>
<br>Visit <a href="/Physics-Interactives/Electric-Circuits">Electric Circuits Interactives</a>.
<br>
</div>
<h3>Magnetism</h3>
<div style="margin-left: 40px;">Observe the interaction between a bar magnet and the needle of a compass with our Magnetic Field Simulator.
<br>
<br>Visit
<a href="/Physics-Interactives/Magnetism">Magnetism Interactives</a>.
<br>
</div>
<h3>Waves and Sound</h3>
<div style="margin-left: 40px;">Explore the nature of a wave and the relationship between waves and sound with the Simple Wave Simulator. Study the motion of waves on a string and the effect of tension, density and damping upon their behavior with the Slinky Lab Interactive.
Create standing waves and investigate their patterns with the Standing Wave Maker Interactive.
<br>
<br>Visit <a href="/Physics-Interactives/Waves-and-Sound">Waves and Sound Interactives</a>
<br>
</div>
<h3>Reflection and Mirrors</h3>
<div style="margin-left: 40px;"><span style="font-size: 12px;">Study plane mirror images with the Who Can See Who? Interactive. Use the Optics Bench Interactive to explore the images formed by concave and convex mirrors. Practice your skill at recognize the characteristics of curved mirror images with the Name That Image Interactive.</span>
</div>
<div style="margin-left: 40px;">
<br>Visit <a href="/Physics-Interactives/Reflection-and-Mirrors">Reflection and Mirrors Interactives</a>.
<br>
</div>
<h3>Refraction and Lenses</h3>
<div style="margin-left: 40px;">Explore the refraction of light at a boundary between two media with the Refraction Interactive. Launch the Least Time Principle Interactive and discover the fundamental law that explains why light refracts as it does when traveling between two locations
on the opposite side of a boundary. Use the Optics Bench Interactive to explore the images formed by converging and diverging lenses.
<br>
<br>Visit <a href="/Physics-Interactives/Refraction-and-Lenses">Refraction and Lenses Interactives</a>.</div>
<h3> </h3>
<br>
<br>
<br>
<br>
<br>
<h2 class="sectionTitle">
</h2>
<br>
<br>
<br>
<br>
<div class="socialShare">
<div class="addthis_toolbox addthis_default_style addthis_32x32_style"><a class="addthis_button_facebook addthis_button_preferred_1 at300b" title="Facebook" href="#"><span class="at4-icon-left at4-icon aticon-facebook" style="background-color: rgb(48, 88, 145);"><span class="at_a11y">Share on facebook</span></span></a>
<a
class="addthis_button_twitter addthis_button_preferred_2 at300b" title="Tweet" href="#"><span class="at4-icon-left at4-icon aticon-twitter" style="background-color: rgb(44, 168, 210);"><span class="at_a11y">Share on twitter</span></span>
</a><a class="addthis_button_email addthis_button_preferred_3 at300b" target="_blank" title="Email" href="#"><span class="at4-icon-left at4-icon aticon-email" style="background-color: rgb(115, 138, 141);"><span class="at_a11y">Share on email</span></span></a>
<a
class="addthis_button_print addthis_button_preferred_4 at300b" title="Print" href="#"><span class="at4-icon-left at4-icon aticon-print" style="background-color: rgb(115, 138, 141);"><span class="at_a11y">Share on print</span></span>
</a><a class="addthis_button_compact at300m" href="#"><span class="at4-icon-left at4-icon aticon-compact" style="background-color: rgb(252, 109, 76);"><span class="at_a11y">More Sharing Services</span></span></a><a class="addthis_counter addthis_bubble_style"
href="#" style="display: inline-block;"><a class="addthis_button_expanded" target="_blank" title="View more services" href="#">39</a><a class="atc_s addthis_button_compact"><span></span></a></a>
<div class="atclear"></div>
</div>
<script type="text/javascript">
var addthis_config = {
"data_track_addressbar": false
};
</script>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-52794c9e3fb5dbdf"></script>
</div>
</div>
&#13;
答案 0 :(得分:2)
仔细查看Selector课程。你需要的是一个合适的组合器。例如,如果你想选择你使用的标题后面的div&#34; h3 + div&#34;,如果你想选择使用&#34; h3,h3 + div&#34;。
然后,您希望使用正则表达式来定义所需的确切标题(在同一页面上查看伪选择器)。以下代码可能对您有所帮助。
String heading = "1-Dimensional Kinematics";
String cssQuery = "h3:containsOwn(" + heading + "), h3:containsOwn(" + heading + ") + div";
Elements elements = doc.select(cssQuery);