欢迎光临
我们一直在努力

从网页上读取源代码,并写入文件-.NET教程,面向对象编程

建站超值云服务器,限时71元/月

private sub downloaddata(byval urlstring as string, byval localfile as string) localfile 是文件的一个完全路径 (包括*.exe)

try

httpwebrequest 类对 webrequest 中定义的属性和方法提供支持,也对使用户能够直接与使用 http 的服务器交互的附加属性和方法提供支持。

dim httpreq as system.net.httpwebrequest

httpwebresponse 类用于生成发送 http 请求和接收 http 响应的 http 独立客户端应用程序。

dim httpresp as system.net.httpwebresponse

dim httpurl as new system.uri(urlstring)

httpreq = ctype(webrequest.create(httpurl), httpwebrequest)

httpreq.method = "get"

httpresp = ctype(httpreq.getresponse(), httpwebresponse)

dim reader as streamreader = new streamreader(httpresp.getresponsestream) 如是中文,要设置编码格式为“gb2312”。

dim resphtml as string = reader.readtoend() resphtml就是网页源代码

dim sw as streamwriter = file.createtext(localfile)

sw.write(resphtml)

sw.close()

httpresp.close()

catch e as exception

console.writeline("getsource出现问题:{0},{1}", e.message, urlstring)

end try

end sub

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 从网页上读取源代码,并写入文件-.NET教程,面向对象编程
分享到: 更多 (0)

相关推荐

  • 暂无文章