0

这是我的代码。我想从 url 中抓取电子邮件。如果给出的 url 是图像 url,有时它会给出 500 错误。我想摆脱该错误来确定函数是否在字符串列表中返回。

       Try
        Dim inStream As StreamReader
        Dim webRequest As WebRequest
        Dim webresponse As WebResponse
        Dim contents As String
        webRequest = webRequest.Create(url)
        webresponse = webRequest.GetResponse()
        inStream = New StreamReader(webresponse.GetResponseStream())
        contents = inStream.ReadToEnd()

        Dim adrRx As Regex = New Regex("\b[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}\b")
        Dim emails As New List(Of String)
        For Each item As Match In adrRx.Matches(contents.ToLower)
            emails.Add(item.ToString)
        Next
        Return emails
    Catch ex As Exception
        Return False
    End Try
4

1 回答 1

0

Nothing如果失败,您应该返回。

然后当然测试结果是否不是什么:

If ScrapeMail(MyUrl) IsNot Nothing Then
        MsgBox("Succes!")
Else
        MsgBox("No succes...")
End If
于 2013-08-02T06:20:45.440 回答