I used Qt before Golang, I can use javascript in Qt like this:
QWebView* view = new QWebView(parent);
view->load(QUrl("http://www.example.com"));
QString cmd("example.value = \"test\""); //using javascript to fill value
view->page()->mainFrame()->evaluateJavaScript(cmd);
QString cmd2("document.forms[\"Form1\"].submit()");//using javascript to submit a Form
QVariant result = view->page()->mainFrame()->evaluateJavaScript(cmd2);
qDebug() << result.toString(); //get javascript return data
How can I use javascript in Golang to get a specific website elements or submit forms.
How can I use javascript in Golang
You can use gopherjs, a compiler from Go to JavaScript.
You can see an example in the tidwall/digitalrain
project, where the digitalrain.go
file access html elements
js.Global.Get("document").Get("head").Call("appendChild", sheet)
js.Global.Get("document").Set("title", "whoa")
(for a great effect)
If you like to run JS code in Go, try Otto (https://github.com/robertkrimen/otto), it's a JS VM written in Go and very powerful.