菜鳥编程园地

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1146|回复: 0

【CBM666 的读取网页源文件】

[复制链接]

34

主题

36

帖子

74

积分

超级版主

Rank: 8Rank: 8

积分
74
QQ
发表于 2020-7-25 09:41:27 | 显示全部楼层 |阅读模式
本帖最后由 cbm666 于 2020-7-25 09:43 编辑


【本代码来源出处:CBM666 VB.NET 编程教材】


Imports System.Net
Imports System.IO
Imports System.Text
Public Class Form1
    Dim TmpStr$, WebAddr$
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Text = "读取网页源文件"
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        WebAddr = "http://www.9900.com.tw/"
        Dim Request As Net.WebRequest = WebRequest.Create(WebAddr)
        Dim Response As WebResponse = Request.GetResponse()
        Dim Stream As IO.Stream = Response.GetResponseStream()
        Dim SR As StreamReader = New StreamReader(Stream, Encoding.GetEncoding("utf-8"))
        TmpStr = SR.ReadToEnd
        If InStr(TmpStr, "gb2312") > 0 Then
            Dim Request2 As Net.WebRequest = WebRequest.Create(WebAddr)
            Dim Response2 As WebResponse = Request2.GetResponse()
            Dim Stream2 As IO.Stream = Response2.GetResponseStream()
            Dim SR2 As StreamReader = New StreamReader(Stream2, Encoding.GetEncoding("gb2312"))
            TmpStr = SR2.ReadToEnd
        End If
        Text1.Text = TmpStr '获得有汉字的完整网页源代码
    End Sub
End Class




WebDocument_net.rar

73.6 KB, 下载次数: 155

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|菜鳥编程园地 ( 蜀ICP备20021315号-1 )

GMT+8, 2022-9-27 14:54 , Processed in 0.175976 second(s), 25 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表