这是我的代码。我想从 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