0
我正在使用刮刀,其中我需要從一個站點刮取數據。我已經厭倦了非常簡單的webclient downloadString來獲取數據,這似乎與其他網站,但有一個問題是我在下面的代碼嘗試。任何幫助將不勝感激。感謝提前。下面的代碼在VB.Net,但我很高興有一個在C#工作的解決方案以及。.Net WebClient DownloadString不能使用混合內容
Private Function GetHtml() As String
Dim mData As String = ""
Try
'ServicePointManager.ServerCertificateValidationCallback = New Security.RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate)
'ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
With mWC
mData = .DownloadString("https://www.adorama.com/brands")
End With
Catch ex As Exception
Debug.Print(ex.Message)
'With CertificateValidationCallback
'The remote server returned an error: (403) Forbidden.
'Without CertificateValidationCallback
'The request was aborted: Could not create SSL/TLS secure channel.
End Try
Return mData
End Function
Private Shared Function ValidateServerCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As Net.Security.SslPolicyErrors) As Boolean
If sslPolicyErrors = Net.Security.SslPolicyErrors.None Then
Return True
End If
Return True
End Function
您能否提出更多關於您的問題的信息。你想做什麼?如果其他網站的工作是什麼這個錯誤? –
@ Youssed13已解決我的問題。請檢查他的答案。感謝您給我的問題留出時間。 – AmitSri