如何解析HTML表中的href-Kotlin

时间:2019-04-23 21:10:22

标签: android kotlin

我尝试通过Kotlin从HTML表格中获取URL。

    <table class="lista-ofert">
    <tbody>
    <tr>...</tr>
    <tr id="of_22833292">
    <td>
    <a href="https://smartclick.pl/click/34c6101ad584d7b93bc9fd9e4c8b3b47,https%25253A%25252F%25252Fwww.pracuj.pl%25252Fpraca%25252Fconsulting-iam-developer-warszawa%25252Coferta%25252C6788281" title="praca Consulting - IAM Developer" target="_blank" onclick="return praca_open_wnd(this.href,1)" data-source="1" data-source-name="Pracuj.pl" onmousedown="praca_redir_go1(1,'https://www.pracuj.pl/praca/consulting-iam-developer-warszawa,oferta,6788281',this,event,'Listing');">
                        <span class="rozwijak" rel="22833292">rozwiń</span>                         <span class="oferta">Consulting - IAM Developer</span>
                        <span class="firma">Accenture Consulting</span>
                    </a>

如何将以下代码更改为有效?

    override fun extractHref(ad: Element) = ad
            .getElementsByClass("lista-ofert")
            .firstOrNull()
            ?.getElementsByTag("a")
            ?.firstOrNull()
            ?.attr("href")
            ?: throw ProviderException(providerName, "Could not parse URL")

0 个答案:

没有答案