如何以文本格式保存网页 [英] How to save the webpage in text format

查看:168
本文介绍了如何以文本格式保存网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想到了为一个小型应用程序进行距离的距离计算,并且想到了一个使用google maps的想法,我可以将url用作

http://maps.google.com/maps?saddr=startadd&daddr=endaddr

但是为了访问我的应用程序,我想将页面保存为文本格式,我可以使用File->Save AS选项卡
我如何通过代码来做到这一点.



请帮助.

Hi all,

I thought of working on distace calculation of routes for a small application, and i came up wit an idea to use google maps for that, I can use the url as

http://maps.google.com/maps?saddr=startadd&daddr=endaddr

but inorder to access in my application i thought of saving the page in text format, i can do it using File->Save AS tab,
how can i do it throug the code.



pls help.

推荐答案

有两种方法可以实现:

解决方案1:
There are two ways to do so :

Solution 1 :
string url = "http://google.com";
string strResult = "";
			
WebResponse objResponse;
WebRequest objRequest = System.Net.HttpWebRequest.Create(url);

//Get the Web Page data
objResponse = objRequest.GetResponse();

using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
    //Read the data
    strResult = sr.ReadToEnd();

    // Close and clean up the StreamReader
    sr.Close();
}

// Display results to a webpage
Response.Write(strResult);



解决方案2:



Solution 2 :

System.Net.WebClient webClient = new System.Net.WebClient();
webClient.DownloadFile("http://www.dotnetspider.com/index.aspx","C:\\spider.html");



检查此链接以获取完整代码 [



Check this link for full code[^]

Hope this helps.
All the best.


这篇关于如何以文本格式保存网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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