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 plex 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
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 plex 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
Share Improve this question edited Jan 11, 2020 at 12:08 Blue Bot asked May 16, 2017 at 11:24 Blue BotBlue Bot 2,4485 gold badges26 silver badges34 bronze badges 4- 3 since go never went upstream in major browsers its highly doubtable you can use go without piling it to javascript first anyways. – GottZ Commented May 16, 2017 at 11:39
- 1 It depends how the site checks for JS. Do you have some code example? – apxp Commented May 16, 2017 at 12:08
- @apxp you mean the sites code? don't have that, as for my code its a precise duplicate of the request sent from the browser (headers wise) – Blue Bot Commented May 16, 2017 at 12:30
- The site's code would be the relevant part. How to get around it depends on how it's being done in the first place. – Adrian Commented May 16, 2017 at 15:27
3 Answers
Reset to default 2Yes, 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./k4s/phantomgo
go get github./k4s/webrowser
- Download the pre-piled binary for your platform of PhantomJS on this page.
- Add the binary to the
$GOPATH/src/github./k4s/phantomgo/phantomgojs
folder.
import (
"fmt"
"io/ioutil"
"net/http"
. "github./k4s/webrowser"
)
func main() {
p := &Param{
Method: "GET",
Url: "http://google.",
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())
}
Try PhantomJS for Go https://github./k4s/phantomgo
I tried it once and it worked for me, maybe it'll help you.
Use Headless Chrome. Here is an example.