Web客户端运行的JavaScript [英] WebClient runs javascript

查看:311
本文介绍了Web客户端运行的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个。 aspx页面,有控制传呼一些JavaScript功能。

I have one. aspx page that has some JavaScript functions that control paging.

我可以运行这个通过网页浏览器内使用下面的方法JavaScript函数 WebBrowser1_DocumentCompleted

I can run this javascript function via webbrowser with the following method within the WebBrowser1_DocumentCompleted

WebBrowser1.Document.Window.DomWindow.execscript ("somefunction();", "JavaScript")

web浏览器很慢,我preFER使用 System.Net.WebClient.DownloadString

有一些方法来运行此脚本与 System.Net.WebClient 方法是更快,或者一些其他的方式?

Has some way to run this script with the System.Net.WebClient methods that are faster, or some other way?

推荐答案

哦,不。 Web客户端 HTTP 的客户,而不是Web浏览器。

Well, no. WebClient is an HTTP client, not a web browser.

这是HTTP客户端遵循HTTP规范;事实,你的HTTP请求导致HTML是无关的客户端。

An HTTP client follows the HTTP spec; the fact that your HTTP requests result in HTML is irrelevant to the client.

一个网络浏览器,另一方面,在除了作为HTTP客户端,也知道如何解析HTML响应(和执行JavaScript等)。

A web browser, on the other hand, in addition to being an HTTP client, also knows how to parse HTML responses (and execute JavaScript, etc.).

看来你正在寻找一种被称为无头的浏览器,它支持加载HTML和JavaScript的运行在DOM,究竟是什么样,你所需要的。无头的浏览器通常也相当快比较正常的浏览器,因为它们不需要做任何呈现

It seems that what you are looking for is called a "headless browser", which supports loading HTML and running JavaScript on the DOM, exactly like you need. Headless browsers are also generally quite fast compared to normal browsers, since they don't need to do any rendering.

有几个无头的浏览器。 的HtmlUnit 的(其可以是<一href="http://blog.stevensanderson.com/2010/03/30/using-htmlunit-on-net-for-headless-browser-automation/">converted对.NET运行)似乎是一个不错的选择一样, envjs (它是用JavaScript编写的,其中的can嵌入.NET )。不幸的是,我有或者没有经验,但他们都看起来超爽,特别是envjs。

There are several headless browsers. HtmlUnit (which can be converted to run on .NET) seems like a good choice, as does envjs (it's written in JavaScript, which can be embedded in .NET). Unfortunately, I have no experience with either, but they both look super-cool, especially envjs.

还有其他替代来的 web浏览器控制,可能会或可能不会快于你的情况,如果你想留在一个控制。

There are also other alternatives to the WebBrowser control which may or may not be faster in your case, if you want to stay with a control.

这篇关于Web客户端运行的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆