【问题标题】:Accessing HTML Table data in Swift在 Swift 中访问 HTML 表格数据
【发布时间】:2017-02-21 14:01:00
【问题描述】:

我在 swift 编码方面相对较新,并且对 GET 请求有些困惑。这是我的目标:我想使用 swift 获取网站表格中的一些数据并将其显示在 iOS 应用程序中。一旦有了数据,我就知道如何制作 iOS 表格。我不明白的是如何使用 HTML GET 请求获取该数据。

我试图访问的数据采用 HTML 格式,如下所示:

<tr class="white_text">
    <td>1</td>
    <td>1464</td>
    <td>Name</td>
    <td>9.86</td>
    <td>3.85</td>
    <td>1228</td>
    <td>28</td>
</tr>

此数据以相同格式重复多次,但信息不同。

感谢任何帮助。

【问题讨论】:

  • 数据不应以原始 HTML 形式返回。它应该以 JSON 的形式返回。数据从服务器返回时是什么样子的?

标签: html ios swift xcode


【解决方案1】:

您是否应该将 JSON 发送到您的应用程序。但是,如果没有其他方法可以将 HTML 数据下载到字符串中,然后使用可用的 pod 库之一对其进行解析。为此,我使用了 hpple。

【讨论】:

    【解决方案2】:

    您好,您可以这样做,有很多选择和可能性,因为一切都是自定义的,取决于您如何应用它。

        // This custom HTML says that the web page fits mobile divices
        let html = """
        <html>
        <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <style> body { font-size: 150% } </style>
        </head>
        <body>
        \(detailItem.body)
        </body>
        </html>
        """
        
        webView.loadHTMLString(html, baseURL: nil) // This method will read the HTML string. Note: that"detailItem is an array of containing parsed JSON data already so I've combined it with HTML and this method will do that rest.
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      • 1970-01-01
      • 2023-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多