Example #1
0
        void hotelListCrawler_OnCompleted(object sender, OnCompletedEventArgs e)
        {
            Console.WriteLine("酒店搜索完成");
            var matches = Regex.Matches(e.pageSoure, "><a[^>]+href=\"*(?<href>/hotel/[^>\\s]+)\"\\s*data-dopost[^>]*><span[^>]+>.*?</span>(?<text>.*?)</a>");

            hotelList.Clear();
            foreach (Match m in matches)
            {
                var hotel = new Hotel
                {
                    HotelName = m.Groups["text"].Value,
                    Uri       = new Uri("http://hotels.ctrip.com" + m.Groups["href"].Value)
                };
                if (!hotelList.Contains(hotel))
                {
                    hotelList.Add(hotel);
                }
            }

            HotelListBox.Invoke(new Action(() =>
            {
                BindingSource bs             = new BindingSource();
                bs.DataSource                = hotelList;
                this.HotelListBox.DataSource = bs;
            }));
        }
Example #2
0
 private void HotelListBox_DataSourceChanged(object sender, EventArgs e)
 {
     HotelListBox.Select();
     button1_Click(sender, e);
 }