Exemplo n.º 1
0
            public List <DetailConfing> GetAllModels()
            {
                List <DetailConfing> detailConfings = new List <DetailConfing>();
                string domain = "https://www.partslink24.com/";
                string path   = "https://www.partslink24.com/vwag/audi_parts/";
                string html   = Site.LoadDocument(URL).DocumentNode.InnerHtml;

                DetailConfing newDetailConfig = DetailConfing.FromJson(getTableJson());

                newDetailConfig.ImageInfo = loadImageInfo();
                detailConfings.Add(newDetailConfig);

                return(detailConfings);

                ImageInfo loadImageInfo()
                {
                    ImageParam imageParam = ImageParam.FromJson(getImageParamJson());
                    ImageInfo  imageInfo  = ImageInfo.FromJson(getImageInfoJson());

                    imageInfo.ImageUrl = MakeImageUrl();
                    return(imageInfo);

                    string getImageParamJson()
                    {
                        string imagePattern = @"""imageViewerParamsUrl"":""(.*?)""";
                        string imageJsonUrl = path + "/" + Regex.Match(html, imagePattern).Groups[1].Value.Replace("\\u0026", "&");

                        return(Site.LoadJsonString(imageJsonUrl));
                    }

                    string getImageInfoJson()
                    {
                        string jsonImageInfoUrl = domain + imageParam.Pathparams.Url + "&cv=1&request=GetImageInfo&ticket=" + imageParam.Pathparams.Ticket;

                        return(Site.LoadJsonString(jsonImageInfoUrl));
                    }

                    string MakeImageUrl()
                    {
                        string ImageSetting = string.Format(@"&rnd=2771&request=GetImage&format={0}&cv=1&bbox=0%2C0%2C1248%2C1413&width={1}&height={2}&scalefac=1&ticket=",
                                                            imageInfo.ImageFormat, imageInfo.ImageWidth, imageInfo.ImageHeight);

                        return(domain + imageParam.Pathparams.Url + ImageSetting + imageParam.Pathparams.Ticket.Trim());
                    }
                }

                string getTableJson()
                {
                    string tabjePattern = @",(""positions"":(.*?)),""lang";

                    return("{" + Regex.Match(html, tabjePattern, RegexOptions.Singleline).Groups[1].Value + "}");
                }
            }