日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Parse a document from a String

發(fā)布時間:2024/4/13 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Parse a document from a String 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標準>>>

Problem

You have HTML in a Java String, and you want to parse that HTML to get at its contents, or to make sure it's well formed, or to modify it. The String may have come from user input, a file, or from the web.

Solution

Use the static?Jsoup.parse(String html)?method, or?Jsoup.parse(String html, String baseUri)?if the page came from the web, and you want to get at absolute URLs (see [working-with-urls]).

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

Description

The?parse(String html, String baseUri)?method parses the input HTML into a newDocument. The?base URI?argument is used to resolve relative URLs into absolute URLs, and should be set to the URL where the document was fetched from. If that's not applicable, or if you know the HTML has a?base?element, you can use the?parse(String html)?method.

As long as you pass in a non-null string, you're guaranteed to have a successful, sensible parse, with a Document containing (at least) a?head?and a?body?element. (BETA: if you do get an exception raised, or a bad parse-tree, please?file a bug.)

Once you have a Document, you can get get at the data using the appropriate methods in Document and its supers?Element?and?Node.


轉載于:https://my.oschina.net/u/553266/blog/296059

總結

以上是生活随笔為你收集整理的Parse a document from a String的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。