简体   繁体   English

如何在Java中使用jsoup解析file.html

[英]how to parse a file.html with jsoup in java

i have file.html,i want to open it and extract the links with jsoup library and show those links in the out put of my program how can i use this library to do this??? 我有file.html,我想打开它并提取与jsoup库的链接,并在程序的输出中显示这些链接,我如何使用该库来执行此操作?

               String html = "<html><head><title>First parse</title></head>"
                + "<body><p>Parsed HTML into a doc.</p></body></html>";
                Document doc = Jsoup.parse(html);

i want to do some thing like that,i want that file.html as String and extract the links of that 我想做这样的事情,我想要file.html作为String并提取该链接

Assuming you the links are in the section, you'd do... 假设您的链接位于该部分中,则可以...

Element body = Document.body()

This would then give you an element object, you could then use... 然后,这将为您提供一个元素对象,然后可以使用...

body.getElementsByAttribute("href");

which would return you a list of Element of objects of all the links. 这将为您返回所有链接的对象的元素列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM