从C#中的网页检索Ajax/JavaScript返回结果 [英] Retrieve ajax/JavaScript return results from webpage in c#

查看:61
本文介绍了从C#中的网页检索Ajax/JavaScript返回结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用c#检索网页的内容.问题在于该网页使用Ajax和JavaScript动态创建和填充HTML元素.

I’m trying to retrieve the content of a webpage in c#. The problem is that the webpage uses Ajax and JavaScript to dynamically create and populate the HTML elements.

我正在谈论的网页是:

The webpage I’m talking about is: http://diseases.jensenlab.org/Entity?order=textmining,knowledge,experiments&textmining=10&knowledge=10&experiments=10&type1=9606&type2=-26&id1=ENSP00000317985

如果使用 httpWebRequest 获取网站的HTML代码,则仅JavaScript调用可见,而内容不可见.那么,如何获得在控制台c#程序中显示在网页上的JavaScript的返回结果?我尝试使用网络浏览器类,但无法正常使用.

If you use httpWebRequest to get the HTML code of the website, only the JavaScript calls are visible and not the content. So how can you get the return results of the JavaScript that is being displayed on the webpage in a console c# program? I have tried using the web browser class but can’t get it to work.

如何在新线程中使用Web浏览器类在 Array List 中显示动态创建的表的结果?此外,如果您不知道名称,该如何访问相关的HTML标记?可以使用ID标签吗?这是假定Web浏览器类是执行此操作的最佳方法.还是有更好的方法?

How do you use the web browser class in a new thread to display the dynamically created table’s results in an Array List? Further how do you access the relevant HTML tag if you do not know the name? Can you use the ID tag? This is assuming that the web browser class is the best way to go about doing this. Or is there a better way?

相关的HTML代码部分是:

The relevant HTML code part is:

<div class="ajax_table" id="53c2583b1f204464d7fa9387e2ac1868"><script>blackmamba_pager('Textmining', 'type1=9606id1=ENSP00000317985type2=-26title=Text+mining',
10, 1, '53c2583b1f204464d7fa9387e2ac1868');</script></div>

请提供一个有关此操作方式的示例吗?

Please provide me with an example of how this is done?

推荐答案

此处.然后,也从堆栈溢出中取出:):

Here. then, also taken from stack overflow :):

WebBrowser mywebBrowser;
private void Form1_Load(object sender, EventArgs e)
{
 mywebBrowser = new WebBrowser();
 mywebBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(mywebBrowser_DocumentCompleted);

 Uri address = new Uri("http://www.cnn.com/");
 mywebBrowser.Navigate(address);
}

 private void mywebBrowser_DocumentCompleted(Object sender,WebBrowserDocumentCompletedEventArgs e)
 {
  //Until this moment the page is not completely loaded
  HtmlDocument doc = mywebBrowser.Document;
  HtmlElementCollection tagCollection;
  tagCollection = doc.GetElement("53c2583b1f204464d7fa9387e2ac1868");
 }

没有像jQuery那样直接通过类名获取元素的方法.如果表div的ID不稳定,则可以使用GetElementsByTagName遍历结果.然后,您可以使用GetAttribute("classname")来匹配您的"ajax_table"类.

There's no direct way to get elements by class name like with jQuery. If id of your table div isn't stable, you might use GetElementsByTagName, iterate through the results. You can then use GetAttribute("classname") to match your "ajax_table" class.

这篇关于从C#中的网页检索Ajax/JavaScript返回结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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