简体   繁体   English

如何获得C#中另一个网站页面的JavaScript函数的结果?

[英]how can i get the result of JavaScript function of another websites page in C#?

我有一个使用其他网站数据的应用程序,所以我如何获取它,因为它使用了一些JavaScript函数来获取该数据,并且不会显示在页面视图源中。

Basically you have to render the webpage and ensure the javascript functions are run (evaluated). 基本上,您必须呈现网页并确保javascript函数已运行(评估)。 You could do this by "borrowing" their javascript files (by linking to them from your own page), but this may not work as you don't know what's in those files - they could be accessing DOM elements that you don't have in your page, or calling to other domains which may prevent them from working correctly. 您可以通过“借用”他们的javascript文件(通过从您自己的页面链接到它们的javascript文件)来执行此操作,但这可能无法正常工作,因为您不知道这些文件中的内容-他们可以访问您没有的DOM元素在您的页面中,或调用其他域可能会阻止它们正常运行。

The easiest way to show the same data is to just host the page inside an iframe on your own page. 显示相同数据的最简单方法是将页面托管在自己页面的iframe中。 If you are looking to do this from a normal client application (ie not a web app) then you will need a browser control that you navigate to the target page. 如果您希望通过普通的客户端应用程序(即非Web应用程序)执行此操作,则将需要一个浏览器控件来导航到目标页面。 If the browser control is invisible you could then scrape values from it and show them in your app, although this is a very clumsy way to do it, and it's debatable about how ethical it is. 如果浏览器控件不可见,则可以从中抓取值并将其显示在应用程序中,尽管这是一种非常笨拙的方式,而且其道德性尚有争议。

如果要另一个网站视图源,请使用HTTPWebRequest获取c#中的响应流。

检查firebug,XHR中的NET选项卡,并检查所请求的资源,然后请求相同的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM