예제 #1
0
        /// <summary>
        /// 根据列表地址获取当前页的写真列表
        /// </summary>
        /// <param name="url">列表地址</param>
        /// <returns></returns>
        public async ValueTask <List <PhotoAlbum> > GetPhotoAlbumsByUrlAsync(string url)
        {
            HtmlDocument htmlDocument = await LoadHtmlHelper.LoadHtmlFromUrlAsync(url);

            //获取所有的li标签
            HtmlNodeCollection htmlNodes = htmlDocument.GetNodes(Meitu131Configs.PhotoAlbumsLisXPath);

            ///html/body/div[1]/div[2]/ul
            if (htmlNodes is not null and {
                Count : > 0
            })
예제 #2
0
        public async Task StartAsync()
        {
            HtmlDocument htmlDocument = await LoadHtmlHelper.LoadHtmlFromUrlAsync(Meitu131Configs.Index);


            FileInfo        fileInfo   = new FileInfo(_categoriesDataPath);
            List <Category> categories = new List <Category>();

            categories = await ReadInfoAsync <List <Category> >(_categoriesDataPath);

            //过去7天了,就重新加载
            if ((DateTime.Now - fileInfo.LastAccessTime).Days < 7)
            {
                categories = await GetPageUrlsByCategoryAsync(htmlDocument);
            }
            if (categories is not null)
            {
                //获取到写真列表数据的集合
                List <CategoryPhotoAlbum> categoryPhotoAlbums = new List <CategoryPhotoAlbum>();

                //没有获取到的
                List <CategoryPhotoAlbum> noDataCategoryPhotoAlbums = new List <CategoryPhotoAlbum>();
                foreach (Category category in categories)
                {
                    CategoryPhotoAlbum categoryPhotoAlbum = new CategoryPhotoAlbum();
                    categoryPhotoAlbum.ParentTitle = category.Title;
                    CategoryPhotoAlbum noDataCategoryPhotoAlbum = new CategoryPhotoAlbum();
                    noDataCategoryPhotoAlbum.ParentTitle = category.Title;



                    foreach (CategoryItem categoryItem in category.Items)
                    {
                        ChildCategoryPhotoAlbum childCategoryPhotoAlbum = new ChildCategoryPhotoAlbum();
                        childCategoryPhotoAlbum.ChildTitle = categoryItem.Title;

                        ChildCategoryPhotoAlbum noDataChildCategoryPhotoAlbum = new ChildCategoryPhotoAlbum();
                        noDataChildCategoryPhotoAlbum.ChildTitle = categoryItem.Title;

                        int page = 1;
                        foreach (string url in categoryItem.PageUrls)
                        {
                            //当前页面所有的写真集合
                            List <PhotoAlbum> photoAlbums = await GetPhotoAlbumsByUrlAsync(url);

                            if (photoAlbums.Count != 0)
                            {
                                childCategoryPhotoAlbum.PagePhotoAlbums.Add(new PagePhotoAlbum
                                {
                                    Page        = page,
                                    PhotoAlbums = photoAlbums
                                });
                            }
                            else
                            {
                                noDataChildCategoryPhotoAlbum.PagePhotoAlbums.Add(new PagePhotoAlbum
                                {
                                    Page        = page,
                                    PhotoAlbums = photoAlbums
                                });
                            }
                            page++;
                        }
                        categoryPhotoAlbum.childCategoryPhotoAblums.Add(childCategoryPhotoAlbum);
                        noDataCategoryPhotoAlbum.childCategoryPhotoAblums.Add(noDataChildCategoryPhotoAlbum);
                    }
                    categoryPhotoAlbums.Add(categoryPhotoAlbum);
                    noDataCategoryPhotoAlbums.Add(noDataCategoryPhotoAlbum);
                }

                string categoryPhotoAlbumsDataPath = Path.Combine(_dataDirectoryPath, "categoryPhotoAlbums.json");
                await WriteInfoAsync(categoryPhotoAlbums, categoryPhotoAlbumsDataPath);

                string noDataCategoryPhotoAlbumsDataPath = Path.Combine(_dataDirectoryPath, "noDataCategoryPhotoAlbums.json");
                await WriteInfoAsync(categoryPhotoAlbums, noDataCategoryPhotoAlbumsDataPath);
                //写真集合都已经拿到,该怎么保存
            }
        }