如何在不影响大小写和换行的情况下获得实际的源代码



我正在使用jsoup获取源代码。我使用的是jsoup 1.13.1版本。当我使用下面的代码获得源代码时,我发现大小写被转换为小写。

Document doc = Jsoup.connect("https://example.com").get();
webview.loadData(doc);

我看到了一些他们更喜欢xml解析器的答案。但我不知道如何使用xml解析器从url解析html。还有一个基本网址,我不明白。我正在处理一个Android应用程序项目。所以任何答案都会对我有帮助。提前感谢

使用与默认解析器不同的解析器很容易,既可以使用XML解析器(保留大小写并禁用漂亮打印(即保留换行符((,也可以使用类似配置的HTML解析器。只需使用Connection#parser((方法:

Document document = Jsoup.connect("https://example.com")
.parser(Parser.xmlParser())
.get();
Document document = Jsoup.connect("https://example.com")
.parser(Parser.htmlParser().settings(ParseSettings.preserveCase))
.get();
document.outputSettings().prettyPrint(false);

相关内容

最新更新