Created
June 13, 2015 15:07
-
-
Save jz5/4d93cc61e663d8aba10e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Main() | |
' ログイン(Cookie の取得) | |
Dim session = GetUserSession("メールアドレス", "パスワード") | |
' マイページ取得(取得した Cookie を付けてアクセス) | |
Dim url = "http://www.nicovideo.jp/my/top" | |
Dim req = WebRequest.CreateHttp(New Uri(url)) | |
req.CookieContainer = New CookieContainer | |
req.CookieContainer.Add(session) | |
Dim html As String | |
Using res = req.GetResponse | |
Using rs = res.GetResponseStream | |
Using sr = New StreamReader(rs) | |
html = sr.ReadToEnd | |
End Using | |
End Using | |
End Using | |
End Sub | |
Private Function GetUserSession(ByVal email As String, ByVal password As String) As Cookie | |
Const path As String = "https://secure.nicovideo.jp/secure/login?site=niconico" | |
Dim req = WebRequest.CreateHttp(New Uri(path)) | |
Dim param = String.Format("mail={0}&password={1}", Uri.EscapeDataString(email), Uri.EscapeDataString(password)) | |
Dim buf = System.Text.Encoding.UTF8.GetBytes(param) | |
req.Method = "POST" | |
req.ContentType = "application/x-www-form-urlencoded" | |
req.ContentLength = buf.Length | |
req.Referer = "https://secure.nicovideo.jp/secure/login_form" | |
req.CookieContainer = New CookieContainer | |
Using rs = req.GetRequestStream() | |
rs.Write(buf, 0, buf.Length) | |
End Using | |
Dim html As String | |
Using res = req.GetResponse | |
Using rs = res.GetResponseStream | |
Using sr = New StreamReader(rs) | |
html = sr.ReadToEnd | |
End Using | |
End Using | |
Dim cookies = req.CookieContainer.GetCookies(New Uri(path)) | |
Return cookies("user_session") ' MEMO: 無い場合は Nothing | |
End Using | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment