我的代码爬到HTML页面,搜索标签,读取网站上的表格并填充tableView。在Swift 2.2中,这就像一个魅力,但是自从我更新了Cocoapods以来,我遇到了这个错误,拒绝这样做。
这是我的功能:
if let secondColumn = rowElement.childAtIndex(1) as? HTMLElement {
title = secondColumn.textContent
.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())
.stringByReplacingOccurrencesOfString("\n", withString: "")
if let urlNode = secondColumn.firstNodeMatchingSelector("a") {
if let urlString = urlNode.objectForKeyedSubscript("href") as? String {
url = NSURL(string: urlString)
if url == nil {
url = NSURL.init(string: "www.mywebsitelink.com")
}
}
}
}
错误是在: urlNode.objectForKeyedSubscript("href") as? String
错误:
从“字符串”下调?'String'只解开可选参数;您是要使用'!'吗?
在此之前,此方法运行良好,并且我完全没有更改此文件中的任何代码。
依存关系:
到目前为止已采取的步骤:
变化图:
请帮忙。
使用以下语法解决了它:
如果让urlString = urlNode [“ href”] {}
不确定是否正确,但是要删除'。'之后的文字。到目前为止似乎工作正常。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句