英文:
Golang Simulate Page Visit : Surf Not Triggering Javascript
问题
我有一个使用Surf(gopkg.in/headzoo/surf.v1
)模拟访问本地网页的Go程序,但似乎页面上的JavaScript没有被执行。为了测试,我让网页向服务器的另一个路由发起ajax调用,服务器将在服务器端输出响应。
<html>
<head>
<script src="jquery.min.js"></script>
</head>
<body>
<script>
$.ajax ({
url : "/test",
type : "GET",
success : function(res) {},
error : function(res) {}
});
</script>
</body>
</html>
然后是用于访问页面的Go Surf函数,该路由也在服务器端输出响应,但ajax请求的响应没有显示出来。
func simulateVisit() {
bow := surf.NewBrowser()
bow.SetUserAgent("LocalCrawler/1.0")
err := bow.Open("http://127.0.0.1/page")
if err != nil { fmt.Println(err) }
}
为了确保这只发生在Surf上,我还使用了Chromedp(github.com/chromedp/chromedp
),它正确地返回了两个响应。
这是Surf的限制还是我做了什么愚蠢的事情?
英文:
I have a Go program that is just simulating a local web page being visited using Surf (gopkg.in/headzoo/surf.v1
) but it seems that the Javascript on the page is not being executed. Just to test I have the web page doing an ajax call to another route on the server that will just output a response on the server side.
<html>
<head>
<script src="jquery.min.js"></script>
</head>
<body>
<script>
$.ajax ({
url : "/test",
type : "GET",
success : function(res) {},
error : function(res) {}
});
</script>
</body>
</html>
Then the Go Surf function to visit the page, this route also outputs a response on the server side which is showing up but the one from the ajax request is not showing up.
func simulateVisit() {
bow := surf.NewBrowser()
bow.SetUserAgent("LocalCrawler/1.0")
err := bow.Open("http://127.0.0.1/page")
if err != nil { fmt.Println(err) }
}
To make sure it is only happening from Surf I also tested it with Chromedp (github.com/chromedp/chromedp
) which gave both responses correctly.
Is this a limitation with Surf or am I doing something silly?
答案1
得分: 4
Surf不包含JS运行时。它支持下载脚本,但不会实际执行它们。
英文:
Surf does not include a JS runtime. It does support the downloading of scripts, but it will never actually execute them.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论