-1

I'm trying to parse this website: http://www.ggjh.co.kr/now/menu.php

with following code:

fileprivate func parseMenuHtml(){

    if let url = URL(string: "http://www.ggjh.co.kr/now/menu.php") {
        do {
            let contents = try String(contentsOf: url)
            print(contents)
        } catch {
            print("error")
            // contents could not be loaded
        }
    } else {
        // the URL was bad!
    }

It doens't works and I used kanna also but didn't work.

I don't know what is going wrong TT. With ~.com, above code works well... .php might be the problem..?

Gaur93
  • 685
  • 7
  • 19
  • 1
    * Please edit your question to make it on-topic as explained in the help page: _Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)._ Moreover, never use `String(contentsOf:)` for downloading data from a remote URL. – Dávid Pásztor Jan 29 '18 at 12:56

1 Answers1

0

please see : How To Get HTML source from URL with Swift

Swift 3 and 4

let myURLString = "https://google.com"
guard let myURL = URL(string: myURLString) else {
    print("Error: \(myURLString) doesn't seem to be a valid URL")
    return
}

do {
    let myHTMLString = try String(contentsOf: myURL, encoding: .ascii)
    print("HTML : \(myHTMLString)")
} catch let error {
    print("Error: \(error)")
}
Clegrand
  • 82
  • 4