私は1つのサイトからデータをスクレープする必要があるスクレーパーに取り組んでいます。私は非常にシンプルな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