File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,22 @@ let text = h1.text().collect::<Vec<_>>();
129
129
assert_eq! (vec! [" Hello, " , " world!" ], text );
130
130
```
131
131
132
+ ### Manipulating the DOM
133
+
134
+ ``` rust
135
+ use html5ever :: tree_builder :: TreeSink ;
136
+ use scraper :: {Html , Selector };
137
+
138
+ let html = " <html><body>hello<p class=\ " hello\ " >REMOVE ME</p></body></html>" ;
139
+ let selector = Selector :: parse (" .hello" ). unwrap ();
140
+ let mut document = Html :: parse_document (html );
141
+ let node_ids : Vec <_ > = document . select (& selector ). map (| x | x . id ()). collect ();
142
+ for id in node_ids {
143
+ document . remove_from_parent (& id );
144
+ }
145
+ assert_eq! (document . html (), " <html><head></head><body>hello</body></html>" );
146
+ ```
147
+
132
148
## Contributing
133
149
134
150
Please feel free to open pull requests. If you're planning on implementing
You can’t perform that action at this time.
0 commit comments