Comments (2)
use visdom::{types::BoxDynError, Vis};
fn main()->Result<(),BoxDynError> {
const HTML:&str = r#"<div><p class="item"></p></div><div></div>"#;
let v_out = Vis::load(HTML)?;
let p = v_out.find("p").get(0).unwrap().outer_html();
let p_clone = Vis::load(p)?;
let p_clone = p_clone.get(0).unwrap();
p_clone.get_attribute("class");
Ok(())
}
这个代码会直接panic
Element node must have a meta field.
也许与这个问题相关
from visdom.
这块的设计的确和 jQuery
不太相同,load
方法加载的可能是整个html页面,也可能是html片段,与 cheeriojs
中的 load 方法更类似。
// jquery 中解析的主要是元素节点
$("<!DOCTYPE html><html></html>").length // 0
$("<html></html>").length // 1
load
方法得到的是个虚拟根节点,根节点上实际上只能进行一些查找操作和节点修改操作,其它操作则可能会报上面的错误,当初为了操作相对方便, load
方法返回的数据类型也是 Elements
,后面有时间打算把它做成单独的类型,限制下它的可操作范围,防止出现上面的操作错误了。感谢反馈建议!
from visdom.
Related Issues (20)
- error: failed to get `mesdoc` as a dependency of package `visdom v0.1.4 HOT 1
- How to remove a DOM element? HOT 6
- No problem, my bad :(
- Please add support for html method for all elements HOT 5
- Navigating sideway with `find` method HOT 2
- set_html and replace_with seems not work HOT 6
- 这么好的项目为什么这么少人知道? HOT 1
- 不可用 HOT 2
- `rphtml` and `htmlentities` APIs changed HOT 3
- Stripping class entirely HOT 2
- Does this support xpath selectors ? HOT 4
- 带:冒号的怎么解析? HOT 9
- 缺少类似jquery的clone HOT 6
- 内存泄漏 HOT 6
- 如何获取节点的tag name(节点名称)? HOT 3
- 将`Result<Elements, Box<dyn Error>>` 改为`Result<Elements, Box<dyn Error + Send>>` HOT 2
- 是否有更好的方式获取 select 元素的值? HOT 4
- Opposite of .has() HOT 4
- doc.find("p:contains('好用')" panicked, only when Chinese characters appear in contains() HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from visdom.