8. Extract attributes, text, and HTML from elements
来源:百度文库 编辑:神马文学网 时间:2024/04/29 06:52:23
Extract attributes, text, and HTML from elements
Problem
After parsing a document, and finding some elements, you'll want to get at the data inside those elements.
Solution
- To get the value of an attribute, use the
Node.attr(String key)
method - For the text on an element (and its combined children), use
Element.text()
- For HTML, use
Element.html()
, orNode.outerHtml()
as appropriate
For example:
String html = "An example link.
";
Document doc = Jsoup.parse(html);Element link = doc.select("a").first();
String text = doc.body().text(); // "An example link"
String linkHref = link.attr("href"); // "http://example.com/"
String linkText = link.text(); // "example""
String linkOuterH = link.outerHtml();
// "example"
String linkInnerH = link.html(); // "example"
Description
The methods above are the core of the element data access methods. There are additional others:
Element.id()
Element.tagName()
Element.className()
andElement.hasClass(String className)
All of these accessor methods have corresponding setter methods to change the data.
See also
- The reference documentation for
Element
and the collectionElements
class - Working with URLs
- finding elements with the CSS selector syntax
8. Extract attributes, text, and HTML from elements
The Easy Way to Extract Useful Text from Arbitrary HTML - AI Depot
How To Extract Text From Images (OCR) – Windo...
Extract private key and certificate from a PKCS12 file
Convert text files from DOS to UNIX and vice versa.
13.Setting the text content of elements
extract
input type=text -HTML元素
ruby系列教材(13):Attributes, Instance Variables, and Methods
利用Minidx Extract-Text Com组件从Word,Xls,Pdf……等文件中读取文本内容 - 祥龙之子 - 博客园
ASP和HTML表单 (ASP and HTML Forms)
Attributes c#
Attributes(c#)
Magnolia extract
htmlcxx - html and css APIs for C++
mercantilism: Definition and Much More from A...
sonar: Definition and Much More from Answers....
Primary FROM rurutia AND 月牙湾
The difference from love and like
The difference from love and like
Christmas: Definition and Much More From Answers
Inspirational Tips and Tools from a Designer
uLFS: Your Manageable and Reusable Linux From...
Skin_制作属于我们自己的Skin,HTML and ASCX