本文介绍了读取HTML页面的SourceCode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序中,我想显示某个URL中提供的页面描述。
现在我想获取该URL的源代码。
获取SourceCode后,我将其保存到数据库中。
我会随时显示。
我试过了
Hi,
In my application I want to show the description of a page which is available in some URL.
Now I want to get the Sourcecode of that URL.
After getting the SourceCode, I will save it into database.
And I will display whenever I want.
I have tried
Method 1:
WebRequest req = WebRequest.Create("http://www.google.com");
WebResponse res = req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
string html = sr.ReadToEnd();
Method 2:
string address = "http://www.google.com/";
using (WebClient wc = new WebClient())
{
string content = wc.DownloadString(address);
}
在这两种方法中,我都遇到了错误。无论是超时还是无法远程连接到网站。
请帮助
In both methods I am facing an error. Either it's timed out exception or unable to connect to the website remotely.
Please help
推荐答案
这篇关于读取HTML页面的SourceCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!