Web浏览器筛选器

时间:2015-02-01 01:45:28

标签: vb.net web browser

我想要一个网站列表(每个网站都在不同的行上),网页浏览器在导航时会检查它们,如果它是当前的网址,那么它将导航回来。下面是我目前创建并失败的一些代码,因为它没有检查每行文本,而下面是一些代码也用当前文本检查文本。

Using sr As New StreamReader("website_lists.txt")
        Dim lined As String
        lined = sr.ReadToEnd()
        Dim scanbox As New TextBox
        scanbox.Multiline = True
        Dim buff As StringBuilder = New StringBuilder
        For Each line In lined
            If TextBox1.Text.Contains(scanbox.Text) Then
                webview.GoBack()
                MsgBox("Infected website! For your own sake stay away!")
            End If
        Next
    End Using
End Sub

有些代码有点做同样的事情:

Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
            Dim f As FileStream = New FileStream(ListBox1.SelectedItem, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
            f = New FileStream(ListBox1.SelectedItem, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
            md5.ComputeHash(f)
            Dim hash As Byte() = md5.Hash
            Dim buff As StringBuilder = New StringBuilder
            Dim hashByte As Byte
            For Each hashByte In hash
                buff.Append(String.Format("{0:X2}", hashByte))
            Next

            If scanbox.Text.Contains(buff.ToString) Then 

有任何建议或帮助吗?提前谢谢。

1 个答案:

答案 0 :(得分:2)

我建议File.Readlines ...有关此方法的更多信息here。你也宣布一个新的文本框,但文本永远不会被设置,这意味着包含不会工作...另一个建议,转向Option Strict对你的朋友。

' Loop over lines in file.
For Each line As String In File.ReadLines("yourfile")
        If TextBox1.Text.Contains(line) Then
            webview.GoBack()
            MsgBox("Infected website! For your own sake stay away!")
            Exit For
        End If
Next