0
我無法將輸出發佈到標籤。我不得不將它轉換爲字符串?它似乎給我的錯誤是:「不能用類型'Int'的索引來標記類型JiNode的值?」請幫助!Swift HTML解析器
var meter = ""
@IBAction func calculate(sender: AnyObject) {
print("start scraping...")
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
let url = NSURL(string: "http://uberestimate.com/costs.php")
let jiDoc = Ji(htmlURL: url!)
if jiDoc != nil {
print("html retrived.\n")
self.scrapeHTML(jiDoc!)
}
}
}
@IBOutlet weak var resultLabel: UILabel!
@IBOutlet weak var endingPoint: UITextField!
@IBOutlet weak var startingpoint: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
private func scrapeHTML(jiDoc: Ji) {
println("parsing...\n")
let bodyNode = jiDoc.xPath("//body")!.first!
var contentDivNode = bodyNode.xPath("//span[@style='font-size:1.3em']").first
if contentDivNode == nil {
print("unexpected format!")
}else{
var cdnArray = contentDivNode[1]
var cdn = cdnArray[0]! as String
self.resultLabel.text = cdn
// println(contentDivNode)
}
return
}
}
你應該分享你正在處理的HTML和你得到的錯誤,以讓其他人明白你的問題 – cezheng
它正在顯示HTML,但它沒有顯示在標籤上。當我嘗試將節點轉換爲字符串時,問題就出現了。然後將'字符串'轉換爲'字符串'。我很困惑如何做到這一點。謝謝你var cdnArray = contentDivNode [1] var cdn = cdnArray [0]! as String self.resultLabel.text = cdn –
這是鏈接到第三方庫https://github.com/honghaoz/Ji –