Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 为什么skrape{it}的官方文档中的示例没有编译_Html_Kotlin_Web Scraping - Fatal编程技术网

Html 为什么skrape{it}的官方文档中的示例没有编译

Html 为什么skrape{it}的官方文档中的示例没有编译,html,kotlin,web-scraping,Html,Kotlin,Web Scraping,这里有一段来自skrape{it}官方的代码示例。它是关于从网站中提取数据的。我正在使用库版本1.0.0-alpha6 import it.skrape.core.htmlDocument import it.skrape.selects.and import it.skrape.selects.eachImage import it.skrape.selects.eachText import it.skrape.selects.html5.a import it.skrape.selects

这里有一段来自skrape{it}官方的代码示例。它是关于从网站中提取数据的。我正在使用库版本1.0.0-alpha6

import it.skrape.core.htmlDocument
import it.skrape.selects.and
import it.skrape.selects.eachImage
import it.skrape.selects.eachText
import it.skrape.selects.html5.a
import it.skrape.selects.html5.div
import it.skrape.selects.html5.p
import it.skrape.selects.html5.span
import org.junit.jupiter.api.Test

// just some object where we will store our scraped data
data class MyExtractedData(
            var httpMessage: String = "",
            var userName: String = "",
            var repositoryNames: List<String> = emptyList(),
            var theThirdRepositoriesName: String = "",
            var firstThreeHrefs: List<String> = emptyList(),
            var overviewLink: String = "",
            var firstThreeImageSources: List<String> = emptyList(),
            var title: String = "",
            var starsCount: String = ""
    )

fun main() {
    val extracted = skrape { // 1️⃣
        url = "https://github.com/skrapeit" 
    
        extractIt<MyExtractedData> { it ->
            it.httpMessage = status { message } // 2️⃣
            htmlDocument { // 3️⃣
                relaxed = true // 4️⃣
    
                it.userName = ".h-card .p-nickname" { findFirst { text } } // 5️⃣
                val repositories = span(".repo") { findAll { this }} // 6️⃣
                println("hello world") // 7️⃣
                it.repositoryNames = repositories.filter { it.text.contains("skrape") }.eachText // 8️⃣
                it.theThirdRepositoriesName = span(".repo") { 
                    2 { text } // 9️⃣
                }
                it.firstThreeImageSources = findAll { eachImage.map { image -> image.value } }.take(3) // 1️⃣0️⃣
                it.firstThreeHrefs = findAll { eachHref }.take(3) // 1️⃣1️⃣ 
                it.overviewLink = findAll { eachLink["Overview"] ?: "not found" } // 1️⃣2️⃣ 
                it.title = titleText // 1️⃣3️⃣
    
                // *️⃣
                it.starsCount = div { // 1️⃣5️⃣ 
                    withClass = "pinned-item-list-item"
                    findFirst {
                        p { // 1️⃣6️⃣
                            findSecond {
                                a {
                                    // 1️⃣7️⃣ 
                                    withClass = "pinned-item-meta" and "muted-link" // 1️⃣8️⃣
                                    withAttribute = "href" to "/skrapeit/skrape.it/stargazers" // 1️⃣9️⃣
    
                                    findFirst {
                                        ownText
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    println(extracted)
}
导入it.skrape.core.htmlDocument
导入it.skrape.selects.and
导入it.skrape.selects.eachImage
导入it.skrape.selects.eachText
导入it.skrape.selects.html5.a
导入it.skrape.selects.html5.div
导入它.skrape.selects.html5.p
导入it.skrape.selects.html5.span
导入org.junit.jupiter.api.Test
//只是一个我们将存储所收集数据的对象
数据类MyExtractedData(
var httpMessage:String=“”,
var userName:String=“”,
var repositoryNames:List=emptyList(),
变量第三个位置名称:String=“”,
var firstThreeHrefs:List=emptyList(),
var overviewLink:String=“”,
var firstThreeImageSources:List=emptyList(),
var title:String=“”,
var starscont:String=“”
)
主要内容(){
val extracted=skrape{//1️⃣
url=”https://github.com/skrapeit" 
提取它{it->
it.httpMessage=状态{message}//2️⃣
htmlDocument{//3️⃣
放松=真//4️⃣
it.userName=“.h-card.p-昵称”{findFirst{text}//5️⃣
val repositories=span(“.repo”){findAll{this}}//6️⃣
println(“你好世界”)//7️⃣
it.repositoryNames=repositories.filter{it.text.contains(“skrap”)}.eachText//8️⃣
it.ThetThirdepositoriesName=span(“.repo”){
2{text}//9️⃣
}
it.firstThreeImageSources=findAll{eachImage.map{image->image.value}。take(3)//1️⃣0️⃣
it.firstThreeHrefs=findAll{eachHref}.take(3)//1️⃣1.️⃣ 
it.overviewLink=findAll{eachLink[“概述”]?:“未找到”}//1️⃣2.️⃣ 
it.title=titleText//1️⃣3.️⃣
// *️⃣
it.starscont=div{//1️⃣5.️⃣ 
withClass=“固定项目列表项目”
findFirst{
p{//1️⃣6.️⃣
findSecond{
a{
// 1️⃣7.️⃣ 
withClass=“固定项目元”和“静音链接”//1️⃣8.️⃣
withAttribute=“href”to”/skrapeit/skrape.it/stargazers//1️⃣9️⃣
findFirst{
ownText
}
}
}
}
}
}
}
}
}
println(摘录)
}
这段代码根本无法编译。所有可能的进口都已完成

错误:

  • 未解析的引用:状态
  • 未解析引用:消息
  • 未解析引用:松弛
  • 应为函数调用“eachText()”(第8行)️⃣ (评论)
  • “Int”类型的表达式“2”不能作为函数调用。未找到函数“invoke()”(第9行)️⃣ (评论)
  • 类型不匹配。必填项:列表。找到:列表(带1的行)️⃣0️⃣ (评论)
  • 这还不是全部。几乎每一行都有很多错误。错在哪里


    谢谢大家!

    我知道我已经有一段时间了,但我昨天第一次看到了这场擦肩而过的比赛,面对着和你一样的问题。 这些家伙在官方文件上有一个错误(可能这只是以前的一种工作方式)

    要使其工作,您需要稍微更改函数的顶部:

    val extracted = skrape(HttpFetcher) { // 1️⃣
                request {
                    url = "https://github.com/skrapeit"
                }
    
    这对我来说是个骗局,希望也能帮助别人