Exemple #1
0
        /// <summary>
        /// 指定された年月の最終ページ番号を取得します。
        /// </summary>
        /// <param name="month">対象年月</param>
        /// <returns>最終ページ番号</returns>
        private async Task <int> GetLastPageNumber(DateTime month)
        {
            //--- 料金明細内訳のトップページを取得
            var billYm   = $"?billYm={month.ToString("yyyyMM")}";
            var uri      = new Uri($"https://bltm11.my.softbank.jp/wcot/billTotal/doBillItems{billYm}");
            var response = await this.Client.GetAsync(uri).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
            var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

            //--- スクレイピングして最終ページを取得
            using (var reader = new StreamReader(stream, Encoding.GetEncoding(932)))
            {
                var @namespace = XNamespace.Get("http://www.w3.org/1999/xhtml");
                var max        = This.ParseHtml(reader)
                                 .Descendants(@namespace + "p")
                                 .SingleOrDefault(x => x.Attribute("class")?.Value == "pagelink")
                                 ?.Elements(@namespace + "a")
                                 .Select(x => x.Attribute("href"))
                                 .Where(x => x != null)
                                 .Select(x => x.Value)
                                 .Select(x => x.Replace("/wcot/billItems/goPaging/", string.Empty))
                                 .Select(x => x.Replace(billYm, string.Empty))
                                 .Select(x =>
                {
                    int value = 0;
                    return(int.TryParse(x, out value) ? value : (int?)null);
                })
                                 .Max();
                return(max ?? 1);
            }
        }
Exemple #2
0
        /// <summary>
        /// オンライン料金案内のCookieをキャッシュします。
        /// </summary>
        /// <returns>処理</returns>
        private async Task CachePriceGuidanceCookieAsync()
        {
            IReadOnlyDictionary <string, string> formData = null;

            {
                //--- オンライン料金案内のリンク先を取得
                var url      = "https://web-meisai.softbanktelecom.co.jp/cgi-bin/meisai/usr/scripts/obi_redirect.jsp";
                var response = await this.Client.GetAsync(url).ConfigureAwait(false);

                response.EnsureSuccessStatusCode();
                var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

                //--- htmlを取得してリダイレクト用のパラメーターを取得
                using (var reader = new StreamReader(stream, Encoding.UTF8))
                {
                    formData = This.ParseHtml(reader)
                               .Descendants("input")
                               .Select(x => new
                    {
                        Name  = x.Attribute("name").Value,
                        Value = x.Attribute("value").Value,
                    })
                               .ToDictionary(x => x.Name, x => x.Value);
                }
            }

            //--- リダイレクト先にPOSTしてCookieを取得
            using (var content = new FormUrlEncodedContent(formData))
            {
                var uri      = new Uri("https://bltm11.my.softbank.jp/wcot/index/");
                var response = await this.Client.PostAsync(uri, content).ConfigureAwait(false);

                response.EnsureSuccessStatusCode();
            }
        }