Exemplo n.º 1
0
        public List <Album> GetAlbums(string girlId)
        {
            var url = GetAlbumsUrl(girlId);
            var s   = _client.GetString(_client.BuildRequest(url));

            var list  = new List <Album>();
            var nodes = s.XPath("//div[@class='igalleryli_div']//img");

            if (nodes == null)
            {
                throw new Exception($"ID为{girlId}的模特作品不存在");
            }
            var regex = new Regex("/(\\d+)/(\\d+)/cover/");

            foreach (var node in nodes)
            {
                var dataOri = node.GetAttributeValue("data-original", null);
                var src     = node.GetAttributeValue("src", dataOri);
                var title   = node.GetAttributeValue("title", null);
                var match   = regex.Match(src);

                list.Add(new Album()
                {
                    Cover  = src,
                    Id     = match.Groups[2].Value,
                    GirlId = girlId,
                    Title  = title,
                });
            }
            return(list);
        }
Exemplo n.º 2
0
        public void Login(string username, string password)
        {
            if (isLoggedIn)
            {
                return;
            }
            var loginUrl = $"{AccountBaseUri}/login";
            var s        = _client.GetString(_client.BuildRequest(loginUrl));
            var match    = Regex.Match(s, "name=\"post_key\".+?value=\"(.+?)\"");

            if (!match.Success)
            {
                throw new Exception("无法获取post_key");
            }
            s = _client.GetString(_client.BuildRequest(loginUrl, new Dictionary <string, object>()
            {
                { "pixiv_id", username },
                { "password", password },
                { "post_key", match.Groups[1].Value },
                { "lang", "zh" },
                { "source", "pc" },
                { "return_to", "https://www.pixiv.net/" },
            }));
            if (GetMyStatus(s) == null)
            {
                throw new Exception("账号或密码有误,登录失败");
            }
        }