当前位置: 首页 > 工具软件 > Ji-parser > 使用案例 >

swift html 转换,Swift HTML Parser

宋昕
2023-12-01

I am having trouble posting the outputs to a label. I have to covert it to a String? The error it seems to give me is "Cannot subscript a value of type JiNode? with an index of type 'Int'" Please help!

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

}

}

 类似资料: