예제 #1
0
        FlatData ParseExtraPage(string URL)
        {
            string        Html     = getHTML(URL);
            var           parser   = new HtmlParser();
            var           document = parser.Parse(Html);
            FlatData      data     = new FlatData();
            List <string> Photos   = new List <string>(100);
            var           cells    = document.QuerySelectorAll("img.simple-gallery-item");

            foreach (var cell in cells)
            {
                string s = cell.GetAttribute("src");
                Photos.Add(s);
            }
            cells = document.QuerySelectorAll("div.text-content p");
            string str = cells[0].TextContent;

            while (str.Contains("  "))
            {
                str = str.Replace("  ", " ");
            }
            data.ExtraInfo = str;
            data.Photos    = Photos;
            return(data);
        }
예제 #2
0
        void Parse(string HTML)
        {
            var           parser    = new HtmlParser();
            var           document  = parser.Parse(HTML);
            List <string> Street    = new List <string>(100);
            List <string> AddStreet = new List <string>(100);
            List <string> price     = new List <string>(100);
            List <string> text1     = new List <string>(100);
            List <string> text2     = new List <string>(100);
            List <string> URLs      = new List <string>(100);

            var cells = document.QuerySelectorAll("div.imd_mid div.md_head em");

            foreach (var cell in cells)
            {
                Street.Add(cell.TextContent);
            }
            cells = document.QuerySelectorAll("div.imd_mid div.md_head em img");
            foreach (var cell in cells)
            {
                AddStreet.Add(cell.GetAttribute("src"));
            }
            for (int i = 0, j = 0; i < Street.Count; i++)
            {
                if (Street[i] == "")
                {
                    Street[i] = AddStreet[j++];
                }
            }
            cells = document.QuerySelectorAll("div.imd_bpic div.itm_price img");
            foreach (var cell in cells)
            {
                price.Add(cell.GetAttribute("src"));
            }
            cells = document.QuerySelectorAll("div.imd_bot a");
            foreach (var cell in cells)
            {
                if (cell.GetAttribute("href") != "javascript:void();")
                {
                    URLs.Add(cell.GetAttribute("href"));
                }
            }
            StackLayout stack = new StackLayout();

            for (int i = 0; i < Street.Count && i < price.Count; i++)
            {
                Image imgStreet  = new Image();
                Image imgPrice   = new Image();
                Label StreatText = new Label();
                if (Street[i].Length < 50)
                {
                    StreatText.Text           = Street[i];
                    StreatText.FontAttributes = (FontAttributes)1;
                    stack.Children.Add(StreatText);
                }
                else
                {
                    string StrSrc  = Street[i].Replace("data:image/gif;base64,", "");
                    byte[] ByteSrc = Convert.FromBase64String(StrSrc);
                    imgStreet.Source        = ImageSource.FromStream(() => new MemoryStream(ByteSrc));
                    imgStreet.HeightRequest = 25;
                    stack.Children.Add(imgStreet);
                }
                FlatData data      = ParseExtraPage(URLs[i]);
                Label    ExtraInfo = new Label();
                ExtraInfo.Text = data.ExtraInfo;
                string StrPrice  = price[i].Replace("data:image/gif;base64,", "");
                byte[] BytePrice = Convert.FromBase64String(StrPrice);
                imgPrice.Source          = ImageSource.FromStream(() => new MemoryStream(BytePrice));
                imgPrice.BackgroundColor = Color.Blue;
                imgPrice.HeightRequest   = 15;

                ListView     listView = new ListView();
                List <Image> photos   = new List <Image>();
                for (int j = 0; j < data.Photos.Count; j++)
                {
                    Image img = new Image();
                    img.Source = "http:" + data.Photos[j];
                    photos.Add(img);
                }
                listView.ItemsSource = photos;
                stack.Children.Add(imgPrice);
                stack.Children.Add(ExtraInfo);
                StackLayout st = new StackLayout();
                st.Orientation = (StackOrientation)1;
                Frame f = new Frame();
                for (int j = 0; j < photos.Count; j++)
                {
                    //if(j != 2)
                    //     stack.Children.Add(photos[j]);
                    st.Children.Add(photos[j]);
                }
                ScrollView a = new ScrollView();
                a.Content     = st;
                a.Orientation = (ScrollOrientation)1;
                f.Content     = a;
                stack.Children.Add(f);
            }
            stack.Padding       = new Thickness(10, 10, 10, 10);
            Interesting.Content = stack;
        }