kotlin读取html,kotlin 使用skrape {it}从html获取数据 - 糯米PHP
查看語法,我假設(shè)您使用的是0.6.0版。您必須使用更特定的CSS選擇器。
data class MyScrapedData(
val userName: String,
val link: String
)
fun main() {
val githubUserData = skrape {
url = "http://www.website"
extract {
MyScrapedData(
userName = el("div.CollapsiblePanel").text(),
link = el("table tr td a").attr("href")
)
}
}
println("selected user: ${githubUserData.userName}")
println("selected link: ${githubUserData.link}")
// will print:
// Today's Interest (1)
// link info i need in here
}
You can find more information about css selectors here: https://www.w3schools.com/cssref/css_selectors.asp
you could also give version 1.0.0-alpha5 a try. I know it's an alpha version, but it's fully working and you could do things even more elegant.
EDIT:
If you want to extract multiple links you can do (using version 0.6.0) it like this:
assuming the HTML you want to parse has following structure:
Today's Interest (1)| description | description | description | description | no link in here |
總結(jié)
以上是生活随笔為你收集整理的kotlin读取html,kotlin 使用skrape {it}从html获取数据 - 糯米PHP的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JDK源码
- 下一篇: php zip下载损坏,php – 从z