Reputation: 2438
Creating a micro service that gets couple websites main pages html. One of them performs a check for enabled JS and redirects to error page if no JS was detected.
Is there a way around it with Golang?
EDIT: attempted to play with this package (JavaScript interpreter) but with no luck..
EDIT2: its 2020, moved to use js Puppeteer
It uses embedded browser and is a very mature and packed with utilities library. for complex web apps embedded browser is really the only one to go
For backends written in other the js I would still use 'Puppeteer' as a micro service
hope this helps anyone in the future
thanks
Upvotes: 4
Views: 5161
Reputation: 652
Yes, it is possible. Like Gonzalez mentioned earlier, PhantomJS is a good choice. But there are some things I would like to clarify, first there is a problem using the phantomgo repository on Linux as the developer doesn't provide the binary of the PanthomJS for Linux.
The way this repository is used should be using the following instructions:
go get github.com/k4s/phantomgo
go get github.com/k4s/webrowser
$GOPATH/src/github.com/k4s/phantomgo/phantomgojs
folder.import (
"fmt"
"io/ioutil"
"net/http"
. "github.com/k4s/webrowser"
)
func main() {
p := &Param{
Method: "GET",
Url: "http://google.com",
Header: http.Header{"Cookie": []string{"your cookie"}},
UsePhantomJS: true,
}
brower := NewWebrowse()
resp, err := brower.Download(p)
if err != nil {
fmt.Println(err)
}
body, err := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
fmt.Println(resp.Cookies())
}
Upvotes: 2
Reputation: 711
Try PhantomJS for Go https://github.com/k4s/phantomgo
I tried it once and it worked for me, maybe it'll help you.
Upvotes: 1