是否可以在webBrowser中加载html页面? [英] It is possible to load a html page in webBrowser?

查看:315
本文介绍了是否可以在webBrowser中加载html页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能在webBrowser BUT中加载一个html页面(在线一个),在将其加载到webBrowser中之前,先将其加载到一个字符串中,然后清理其中的一些标签,然后将该字符串加载到webBrowser中 ?
还是其他任何变体?
我想将网页中的某些标签加载到我的webBrowser中,而不是整个原始页面中(例如,仅列表或特定页面中的图像)加载到我的网页中.
能做到吗?
我想它必须在 php 的帮助下完成,但我不知道.
再次感谢.

例如:
如果我必须加载此页面: http://translate.google.co.uk/?hl= zh-TW& tab = TT
我希望能够摆脱该页面内的"<< pre> div id ="gb"> . (该 div 是该页面的顶部菜单).

It is possible to load a html page(online one) in webBrowser BUT, Before loading it into webBrowser, to load it into a string, clean some tags there, and Then loading that string into webBrowser ?
Or any other variant?
I want to load certain tags from a web page into my webBrowser, and NOT the whole original page.(for example only a list, or only the images- from a specific page)
Can be done?
I suppose it must be done with the help of php, but i dont know it.
Thanks, once again.

For example:
If I have to load this page: http://translate.google.co.uk/?hl=en&tab=TT
I want to be able to get rid of the " <<pre>div id="gb">" INSIDE that page. (That div is the top menu from that page).

推荐答案

您可以分两步进行操作.

1)从HTML文件读取内容. -

您可以使用WebClient()读取HTML文件的内容.
You may do this in two steps.

1) Read content from HTML file. -

Either you can read content of your HTML file using WebClient().
client = new WebClient();
String htmlString = client.DownloadString("MyFile.htm");



或使用StreamReader.



Or using StreamReader.

String htmlString = String.Emtpy;
using( StreamReader reader = new StreamReader( @"MyHtmlFilePath" ) )
{
   htmlString = reader.ReadToEnd(); 
}



2)然后使用DocumentText属性修改htmlString并将其分配给 WebBrowser 控件.请查看下面的链接以获取有关此信息的更多信息.

http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documenttext.aspx

我还发现下面的链接很有趣.

http://geekswithblogs.net/dotnetnomad/archive/2008/01/29/119065.aspx

更新-由于您更新了问题.



2) Then modify your htmlString and assign it to WebBrowser Control using DocumentText Property. Have a look at below link for more information on this.

http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documenttext.aspx

I also found below link interesting.

http://geekswithblogs.net/dotnetnomad/archive/2008/01/29/119065.aspx

Update - Since you updated your Question.

报价:

我想它必须在php的帮助下完成,但我不知道.

I suppose it must be done with the help of php, but i dont know it.


为什么要为此使用PHP?您可以使用简单的StringBuilder或" HTML Agility Pack "来修改/处理HTML字符串.

http://htmlagilitypack.codeplex.com/


Why you need PHP for this? You can modify/manupulate your HTML sting using simple StringBuilder or using "Html Agility Pack".

http://htmlagilitypack.codeplex.com/


您是否尝试过设置DocumentText财产?

Have you tried setting the DocumentText property?

WebBrowser1.DocumentText = "<html><head><title>Hi</title></head><body>Hello world!</body></html>";


您可以通过以下代码将任何HTML页面加载到您的WebBrowser中:
You can load any HTML Page into the Your WebBrowser through code :
System.Uri PagePath;
System.Uri.TryCreate("HTML File Path", UriKind.RelativeOrAbsolute,out PagePath);
WebBrowser1.Url = PagePath;


这篇关于是否可以在webBrowser中加载html页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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