0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

おいCookie食わねぇか

Posted at

#こんなことありませんか
何かしらの認証の必要なwebサイトにあるリンク先を
WebBrowserクラスを使って色々やってからWebClientを使って
ダウンロードしたいときにクッキーを食わせる方法。

#こんなかんじでできます

    Private Sub hoge()
        Dim wc As New WebClient
        Dim eLinks As HtmlElementCollection = wb1.Document.GetElementsByTagName("a")

        For i As Integer = 0 To eLinks.Count - 1
            '必要なら適当に弾く条件を作る

            'とりあえずtempに保存
            Dim saveTo As String = String.Format("{0}\{1}", My.Computer.FileSystem.SpecialDirectories.Temp, eLinks(i).InnerText)

            'おいCookie食わねぇか
            wc.Headers.Add("Cookie", wb1.Document.Cookie)
            wc.DownloadFile(eLinks(i).GetAttribute("href"), saveTo)
        Next i

        wc.Dispose()
    End Sub

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?