如何在c#的浏览器控件中显示屏幕转义的网页 [英] How do you display screen scaped web pages in a browser control in c#

查看:294
本文介绍了如何在c#的浏览器控件中显示屏幕转义的网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在用c#查看屏幕抓取网页,我使用了一些来自Internet的示例代码来做到这一点,并且它可以正常工作.但是我现在要做的是在Windows窗体上的浏览器控件中显示网页,我该怎么做?

我用过的这是我的代码

So i''ve been looking at screen scrapping web pages in c# and I used some example code from the internet to do this and it works. But what I want to do now is to display the web page in a browser control on a windows form, how would I do this?

heres my code i''ve used

private void Page_Load(object sender, System.EventArgs e)
{
//Retrieve URL from user input box
if(Page.IsPostBack)
litHTMLfromScrapedPage.Text = GetHtmlPage( tbURL.Text );
}
public String GetHtmlPage(string strURL)
{
// the html retrieved from the page
String strResult;
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
// the using keyword will automatically dispose the object 
// once complete
using (StreamReader sr = 
new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return strResult;
}

推荐答案

这有点麻烦,具体取决于您是否具有指向图像的链接或其他具有相对路径的链接.

如果您不这样做,那就很简单:
如果在"myString"中包含HTML,
It''s a bit of a pain, depending on whether you have links to images, or anything else with relative paths.

If you don''t, then it''s pretty easy:
myWebbrowser.DocumentText = myString

将指定要显示的内容.

如果这样做,则需要创建一个HTML文件,然后使用:

will specify what you want to display if you have the HTML in "myString".

If you do, then you need to create an HTML file, and then use:

myWebBrowser.Navigate(@"file:\\" + path);


这篇关于如何在c#的浏览器控件中显示屏幕转义的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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