[英]How can I use java,html or javascript to convert relative href attributes into absolute paths?
I would like to open an html file locally (not fetch it from a server) and somehow ensure that the relative hrefs are turned correctly resolved. 我想在本地打开一个html文件(而不是从服务器获取它),并以某种方式确保正确解决了相对href的问题。 I suppose I need to convert them into absolute paths.
我想我需要将它们转换为绝对路径。
I played around with the html element, in the head of the document, to resolve any relative links on the page, but only had limited success (often the resources could not be found). 我在文档的开头使用了html元素,以解决页面上的任何相对链接,但是成功有限(通常找不到资源)。
I can convert the html source file anyway I wish with java, but ideally I would like to modify the html source as little as possible, for example insert a function that modifies the result of the hrf attribute. 无论如何,我都可以使用java转换html源文件,但理想情况下,我希望尽可能少地修改html源,例如,插入一个修改hrf属性结果的函数。
How would I go about this? 我将如何处理? Do any of the java html parsers do this?
是否有任何Java html解析器可以做到这一点?
Thanks 谢谢
If you want to do it on your own, I recommend you to read the chapter Reference Resolution in RFC 3986 . 如果要自己执行此操作,建议您阅读RFC 3986中的参考分辨率一章。 It explains how to establish the base URI and how to resolve relative URIs by giving an algorithm.
它说明了如何建立基本URI以及如何通过给出算法来解析相对URI。
But there's probably already a library in Java that does that for you. 但是Java中可能已经有一个库可以为您完成此工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.