如何在Go中获得Ajax响应

I have used net/http package to get url html response, it works fine until now.
but when I get one page that use Ajax to fill some html element, I could not get all contents of html page.

How can use http.Get that will wait page load completely then get whole web page contents. Thanks!

response, err := http.Get(url)
if err != nil {
    fmt.Printf("%s", err)
    os.Exit(1)
} else {
    defer response.Body.Close()
    contents, err := ioutil.ReadAll(response.Body)
    if err != nil {
        fmt.Printf("%s", err)
        os.Exit(1)
    }
    fmt.Printf("%s
", string(contents))
}

Content generated via javascript isn't part of the HTML that the server is sending out. It needs to be evaluated client-side, and since your client in the case is a Go program you will need to do that evaluation yourself.

A library like Otto may help. However, depending on your needs, it may even be better to re-evaluate your tools and make use of a headless "browser" like PhantomJS or similar.

What you are asking is not possible with a plain HTTP library: you also need the DOM and JavaScript portions of the web browser, and probably even layout depending on what the script does. So rather than the net/http package, you'd probably be better off looking at how to script a web browser to do what you want, or use an embeddable web browser library.

Alternatively, you could try reverse engineering what the AJAX script in the web page is doing. If you can determine what HTTP calls it is performing, one might provide the information you are after. It might also provide the information in an easier to process form like JSON or XML. The web developer tools features in Firefox and Chrome can be quite helpful for this kind of task.