Example #1
0
        public DetailResult GetMovieDetail(string movieDetailPageUrl, int Id)
        {
            Console.WriteLine(Id);
            var          helper   = new CrawlerHelper();
            var          html     = helper.DownloadHtml(movieDetailPageUrl, Encoding.GetEncoding("GB2312"));
            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(html);
            HtmlNode node = document.DocumentNode.SelectSingleNode("/html/body/div[4]/div[1]/div[3]");

            if (node == null)
            {
                return(null);
            }
            var movieName = node.SelectSingleNode("child::div[1]");

            if (movieName == null)
            {
                return(null);
            }
            HtmlNode imgNode = node.SelectSingleNode("child::div[3]/p[1]/img");
            string   ImgUrl  = imgNode != null?imgNode.GetAttributeValue("src", "") : "";

            string Overview = node.SelectSingleNode("child::div[3]/p[2]") != null?node.SelectSingleNode("child::div[3]/p[2]").InnerHtml : "";

            string Introduction = node.SelectSingleNode("child::div[3]/p[3]") != null?node.SelectSingleNode("child::div[3]/p[3]").InnerHtml : "";

            string downloadPageUrl = node.SelectSingleNode("child::div[3]/div[1]/a") != null?node.SelectSingleNode("child::div[3]/div[1]/a").GetAttributeValue("href", "") : "";

            HtmlNodeCollection downloadNodes = null;

            if (downloadPageUrl == "")
            {
                downloadNodes = node.SelectNodes("child::div[3]/div");
            }
            var movie = new AinunuMovieDTO()
            {
                id           = Id.ToString(),
                MovieId      = Id,
                Name         = movieName.InnerText,
                ListImgUrl   = ImgUrl,
                ImgUrl       = ImgUrl,
                Overview     = Overview,
                Introduction = Introduction,
                DownloadUrl  = downloadPageUrl,
                CreateDate   = DateTimeOffset.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")
            };

            return(new DetailResult()
            {
                movie = movie,
                downloadNodes = downloadNodes
            });
        }
Example #2
0
        private async Task InsertMovieIntoCosmos(AinunuMovieDTO movie)
        {
            try
            {
                // Read the item to see if it exists.
                ItemResponse <AinunuMovieDTO> movieResponse = await this.detailContainer.ReadItemAsync <AinunuMovieDTO>(movie.id, new PartitionKey(movie.partitionKey));

                Console.WriteLine("Item in database with id: {0} already exists\n", movieResponse.Resource.id);
            }
            catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                // Create an item in the container representing the Andersen family. Note we provide the value of the partition key for this item, which is "Andersen"
                ItemResponse <AinunuMovieDTO> movieResponse = await this.detailContainer.CreateItemAsync <AinunuMovieDTO>(movie, new PartitionKey(movie.partitionKey));

                // Note that after creating the item, we can access the body of the item with the Resource property off the ItemResponse. We can also access the RequestCharge property to see the amount of RUs consumed on this request.
                Console.WriteLine("Created item in database with id: {0} Operation consumed {1} RUs.\n", movieResponse.Resource.id, movieResponse.RequestCharge);
            }
        }