JSoup - abs:href 获取的绝对地址为空问题
2021-03-19 13:23
标签:splay isp reac 相对 foreach 绝对路径 lan attr eval JSoup - abs:href 获取的绝对地址为空问题 标签:splay isp reac 相对 foreach 绝对路径 lan attr eval 原文地址:https://www.cnblogs.com/duchaoqun/p/12755008.htmlSummary
Demo
val urlList = Jsoup.parse(html,"https://www.jianshu.com/").getElementsByAttributeValue("target","_blank").select(".title")
println(urlList)
println(htmlPage.getBaseURL)
urlList.forEach(
// Element:
x => {
println(x.absUrl("href"))
println(x.absUrl("abs:href"))
}
)
def getContentUrls: List[URL] = {
val listBuffer = new ListBuffer[URL]
val urlList = Jsoup.parse(html).select("""a[href~=.*?.html]""")
urlList.foreach(x => {
val url = new URL (x.attr("abs:href")) // 获取元素A Element 的绝对路径信息
logger.info("获取URL的绝对路径信息: " + url)
listBuffer += url
})
listBuffer.toList
}
文章标题:JSoup - abs:href 获取的绝对地址为空问题
文章链接:http://soscw.com/index.php/essay/66246.html