登录
首页 » Windows开发 » 获取网页源代码的三种方法,并将其保存到文件中

获取网页源代码的三种方法,并将其保存到文件中

于 2023-06-27 发布 文件大小:21.32 kB
0 167
下载积分: 2 下载次数: 1

代码说明:

应用背景在这组片段,我现在给你的三个方法,下载并保存到一个文件中的一个网页的源代码,有兴趣。第一个使用WebClient类和第三个使用WebRequest。它们都是系统的一部分,净名称空间。你应该注意通过HttpWebRequest获取源被认为是一种过时的做法。关键技术让我们先从几个使用语句开始:利用系统;使用System.IO;使用system.windows.forms;注:由于我们使用的控制台应用程序,在这个例子中,请注意system.windows.forms命名空间是不包括在新项目自动所以你要增加它的引用(解决方案资源管理器- & gt;引用& gt;(右击)添加引用比下。净标签找到命名空间)。不包括下面的代码在main()功能:和公司;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及;及使用(WebClient客户端=新webclient()){客户端下载文件。(“HTTP:/ / www.google。COM”,application.startuppath + @“LOG1。txt”);}/ /方法2字符串源=新webclient()。downloadstring(“HTTP:/ / www.google。COM”);StreamWriter SW =新StreamWriter(application.startuppath + @“log2。txt”,真的);软件:写(来源);申银万国();/ /方法3 -过时WebRequest req = HttpWebRequest。创造(“HTTP:/ / www.google。COM”);方法=“得到”的要求;串供应链;(读者使用StreamReader =新的StreamReader(REQ。getresponse()。getresponsestream())){readtoend() SC =读者;}将作家=新StreamWriter(application.startuppath + @“log3。txt”,真的);作者:写(源);作家();此代码将创建包含源代码的三个文本文件(在我们的情况下,谷歌的索引页)。你可以在同一个目录中找到这些文件作为可执行文

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • database comparison tool to import the database to link more library the same na...
    数据库比较工具,分别输入要连接的数据库,比较库中相同名字的表的字段是否相同,相同表名前会自动打勾,结果得出相同字段有多少,表a比表b多出的字段是什么,少的是什么。-database comparison tool to import the database to link more library the same name of the table if a field is the same as before the same table name will be automatically checked, the outcome of the same field, there is a table Table b more than the field what is what is missing.
    2022-06-27 07:43:34下载
    积分:1
  • 监控别人计算机的程序
    监控别人计算机的程序-computer monitoring procedures
    2022-08-16 06:23:21下载
    积分:1
  • 采用ic编写的handyboard机器人的中学组3号房间的程序,(2005年浙江省的规则)...
    采用ic编写的handyboard机器人的中学组3号房间的程序,(2005年浙江省的规则)-used ic handyboard prepared by the robot on the 3rd secondary room procedures, (2005 Zhejiang Rules)
    2022-12-11 03:55:03下载
    积分:1
  • sl会员商城素材
    这是一个大型的企业sl会员商城的项目素材,需要这方面的学习的可以下载来做,做的来绝对日你受益匪浅
    2022-01-25 14:43:25下载
    积分:1
  • 2005最新C++经典著作 2005最新C++经典著作
    2005最新C++经典著作 2005最新C++经典著作-2005最新C++经典著作Addison.Wesley.Effective.C.Plus.Plus.55.Specific.Ways.to.Improve.Your.Programs.and.Designs.3rd.Edition.May.2005.eBook-DDU.chm Addison.Wesley,.C++.Common.Knowledge.Essential.Intermediate.Programming.(2005).chm Addison.Wesley.-.Exceptional.C++.Style.40.New.Engineering.Puzzles,.Programming.Problems.and.Solutions.-.Herb.Sutter.chm Addison.Wesley,.C++.Coding.Standards.101.Rules.Guidelines.(2004).LiB.chm Addison.Wesley.-.Imperfect.C++.Practical.Solutions.for.Real-Life.Programming.chm
    2022-03-16 20:27:18下载
    积分:1
  • 一个用c++编写的程序,希望对初学者有一定帮助
    一个用c++编写的程序,希望对初学者有一定帮助-A used c++ Preparation procedures, and they hope to have some help for beginners
    2022-06-19 22:00:04下载
    积分:1
  • 支持透明显示的滚动框
    支持透明显示的滚动框 -support transparency shown in a rolling box
    2022-07-07 23:36:28下载
    积分:1
  • Game theory related to well
    博弈论相关著名电子书籍,包括张维迎的博弈论与信息经济学、纳什博弈论论文集等完整学习博弈论的书籍-Game theory related to well-known e-books, including Zhang Weiying game theory and information economics, game theory, Nash game theory to study the full proceedings and other books on
    2022-01-31 22:35:22下载
    积分:1
  • gis 系统 vc 的简单入门级别的gis系统
    gis 系统 vc 开发的简单入门级别的gis系统-gis
    2022-02-25 06:22:38下载
    积分:1
  • ThinkingC++中文版,适合初级c++学习者阅读 03部分
    ThinkingC++中文版,适合初级c++学习者阅读 03部分-ThinkingC++ Chinese version, suitable for primary c++ Learners read the 03 part
    2022-04-17 06:34:02下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载