作者:紫猫1_696_267 | 来源:互联网 | 2023-07-20 11:39
IhavealltheHTMLcodeforapageoftheVermontLotteryswebsite(thispage).Inthatpage,ther
I have all the HTML code for a page of the Vermont Lottery's website (this page). In that page, there's this giant table:
我拥有佛蒙特州彩票网站(本页)页面的所有HTML代码。在那个页面中,有一个巨大的表:
I am fetching the HTML of that page successfully with this code (in a Playground):
我使用此代码(在Playground中)成功获取该页面的HTML:
import UIKit
import Foundation
import PlaygroundSupport
let url:URL = URL(string: "https://vtlottery.com/games/instant-tickets/outstanding-prizes")!
let session = URLSession.shared
let request = NSMutableURLRequest(url: url)
request.httpMethod = "POST"
request.cachePolicy = NSURLRequest.CachePolicy.reloadIgnoringCacheData
let paramString = "data=Hello"
request.httpBody = paramString.data(using: String.Encoding.utf8)
let task = session().dataTask(with: request as URLRequest) {
(
data, response, error) in
guard let data = data, let _:URLRespOnse= response where error == nil else {
print("error")
return
}
let dataString = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
print(dataString!)
}
task.resume()
PlaygroundPage.current.needsIndefiniteExecution = true
How can I go about fetching the data from the table in such a way that I can turn it into a giant JSON hash table (or similar)?
我怎样才能从表中获取数据,以便将其转换为巨大的JSON哈希表(或类似的)?
Basically, I want that the HTML code of that chart to turn into something like:
基本上,我希望该图表的HTML代码变成以下内容:
"row 1": {
"Price":"$20",
"Game #":"1333",
"Game Name":"Money"
"Top Prizes":["$150000", "$5000", "$500"],
"Unclaimed Top Prizes":["2", "16", "246"],
"Total Unclaimed":"$2479510",
"% Sold": "1",
"# Of Tickets":"183600"
},
"row 2": {
"Price":"$10",
"Game #":"1339",
"Game Name":"Diamonds & Pearls"
"Top Prizes":["$50000", "$5000", "$500"],
"Unclaimed Top Prizes":["3", "5", "174"],
"Total Unclaimed":"$1264925",
"% Sold": "4",
"# Of Tickets":"201650"
}, ... (etc.)
How can I begin to go about parsing that data?
我怎样才能开始解析这些数据?
1 个解决方案