错误在webbrowser中获取数据 [英] Error get data in webbrowser

查看:68
本文介绍了错误在webbrowser中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在有一个表单和一个webbrowser我想检索webbrowser上显示的数据必须做什么?



Div标签:

 <   div     id   =  divTop   >  
< div id = text-conent
style = <跨度class =code-keyword> width:500px;
float:right;
>
< / div >
< span class =code-keyword>< div id = grid
样式 = margin-删除505px;
身高:700px;
>
< / div >
< span class =code-keyword>< / div >



代码从webbrowser获取数据:

 HtmlAgilityPack.HtmlDocument doc; 
string 文本

doc =(HtmlAgilityPack.HtmlDocument)webBrowser1。
Document。
DomDocument;
texts = doc。 DocumentNode.SelectSingleNode(
// div [@ class ='text-conent'] / p] )。InnerText;
richTextBox1.Text =文本;





错误:

无法将类型为mshtml.HTMLDocumentClass的COM对象强制转换为类类型HtmlAgilityPack.HtmlDocument。表示COM组件的类型实例不能转换为不代表COM组件的类型;但是只要基础COM组件支持IID的QueryInterface调用,它们就可以转换为接口



我必须如何在正确的webbrowser

解决方案

HtmlAgilityPack.HtmlDocument与mshtml.HTMLDocumentClass不兼容。在代码的某处,你可能会将webBrowser1指向一个文件,你要从中提取divtext-conent的内部文本(你确定要拼写吗?)。



我建议您按照我在 SiteMapper工具 [< a href =http://www.codeproject.com/Articles/786768/SiteMapper-Tooltarget =_ blank> ^ ]

 HAP.HtmlDocument web_page =  new  HAP.HtmlDocument(); 

尝试
{
WebRequest web_request;
WebResponse web_response;

web_request = WebRequest.Create(uri.AbsoluteUri);
web_response = web_request.GetResponse();

使用(Stream stream = web_response。
GetResponseStream())
{
web_page.Load(流);
}
}
catch (WebException we)
{
node.Broken = ;
继续;
}





只需使用HtmlAgilityPack Load方法即可。我建议你永远不要使用mshtml.HTMLDocumentClass。



一旦你在web_page中有了HTML,就可以像你现在一样提取div内部文本。


have a form and one webbrowser now I want to retrieve data displayed on the webbrowser must do?

Div Tags:

<div id="divTop" >
  <div id="text-conent"
       style="width: 500px;
              float: right;" >
  </div>
  <div id="grid"
       style="margin-removed 505px;
              height: 700px;" >
  </div>
</div>


Code get data from webbrowser:

HtmlAgilityPack.HtmlDocument doc;
string                       texts

doc = ( HtmlAgilityPack.HtmlDocument ) webBrowser1.
                                       Document.
                                       DomDocument;
texts = doc.DocumentNode.SelectSingleNode (
            "//div[@class='text-conent']/p]").InnerText;
richTextBox1.Text = texts;



Error:
Unable to cast COM object of type 'mshtml.HTMLDocumentClass' to class type 'HtmlAgilityPack.HtmlDocument'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID

I have to how to get the data in the correct webbrowser

解决方案

HtmlAgilityPack.HtmlDocument is not compatible with mshtml.HTMLDocumentClass. Somewhere in your code, you probably point webBrowser1 to a file from which you want to extract the inner text of the div "text-conent" (are you sure of the spelling?).

I'd suggest that you follow the process that I used in SiteMapper Tool[^]

HAP.HtmlDocument  web_page = new HAP.HtmlDocument ( );

try
    {
    WebRequest  web_request;
    WebResponse web_response;

    web_request = WebRequest.Create ( uri.AbsoluteUri );
    web_response = web_request.GetResponse ( );

    using ( Stream stream = web_response.
                            GetResponseStream ( ) )
        {
        web_page.Load ( stream );
        }
    }
catch ( WebException we )
    {
    node.Broken = true;
    continue;
    }



Simply use the HtmlAgilityPack Load method. I suggest that you never use the mshtml.HTMLDocumentClass.

Once that you have the HTML in web_page, you can extract the div inner text as you are currently doing.


这篇关于错误在webbrowser中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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