简体   繁体   English

类型'XPathObject'的值没有成员'text'

[英]Value of type 'XPathObject' has no member 'text'

I am trying to replicate the for loop without using a loop, which works and is commented out. 我试图在不使用循环的情况下复制for循环,该循环有效并且已被注释掉。

How can I access the text member without using a for loop? 如何在不使用for循环的情况下访问文本成员?

if let doc = try? Kanna.HTML(html: htmlText, encoding: .utf8)
{
    for item in doc.css("div[class^='test']")
    {
        print("item: \(count)")                                           
        let itemName = item.css("p[class^='hello']")
        /*
        for itemName in item.css(("p[class^='hello']"))
        {
            print(itemName.text!)
        }
        */
        print(itemName.text!) // error here
        count += 1
    }
}

I fixed the error by doing print(itemName.first!.text!). 我通过执行print(itemName.first!.text!)解决了该错误。

Gets the first xmlelement. 获取第一个xmlelement。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM