Ejemplo n.º 1
0
        private void SetValueToListView(List <HistoryItem> list)
        {
            listviewURL.Items.Clear();
            int Count = 1;

            listviewURL.SmallImageList = imageList1;
            foreach (HistoryItem item in list)
            {
                HttpsToHttp cv = new HttpsToHttp(item.URL);
                item.URL = cv.Convert();
                GetContentFromURL getc    = new GetContentFromURL(item);
                String            content = getc.ExtractContentFromUrl();
                ListViewItem      lvi;
                if (content == "")
                {
                    lvi = new ListViewItem("", 1);
                }
                else
                {
                    lvi = new ListViewItem("", 0);
                }
                lvi.SubItems.Add(item.URL);
                lvi.SubItems.Add(item.Title);
                lvi.SubItems.Add(item.VisitedTime.ToString());

                lvi.SubItems.Add(getc.ExtractContentFromUrl());
                lvi.SubItems.Add("BT");
                listviewURL.Items.Add(lvi);
                Count++;
            }
        }
Ejemplo n.º 2
0
 private void btnQuet_Click(object sender, EventArgs e)
 {
     if (txtDiaChi.Text == "")
     {
         XtraMessageBox.Show("Lỗi: Chưa nhập địa chỉ URL", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         if (!CheckValidURL(txtDiaChi.Text))
         {
             XtraMessageBox.Show("URL không hợp lệ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             LoadingInForm loading = new LoadingInForm(splashScreenManager1);
             loading.ShowWaitForm();
             RemovePreviousSeries();
             String      url = txtDiaChi.Text;
             HttpsToHttp cv  = new HttpsToHttp(url);
             url = cv.Convert();
             GetContentFromURL get     = new GetContentFromURL(new HistoryItem(url, "", DateTime.Now));
             String            content = get.ExtractContentFromUrl();
             if (content != "")
             {
                 XayDungBieuDo(content);
                 loading.CloseWaitForm();
             }
             else
             {
                 loading.CloseWaitForm();
                 XtraMessageBox.Show("Không thể tải nội dung từ URL", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
Ejemplo n.º 3
0
        //Quét mã nguồn html, phân tích các thẻ image để trích xuất hình ảnh
        private List <string> ScanImage(string Url)
        {
            List <string> imageList = new List <string>();

            if (!Url.StartsWith("http://") && !Url.StartsWith("https://"))
            {
                Url = "http://" + Url;
            }
            HttpsToHttp cv = new HttpsToHttp(Url);

            Url = cv.Convert();
            string responseUrl = string.Empty;
            string htmlData    = ASCIIEncoding.ASCII.GetString(DownloadData(Url, out responseUrl));

            if (responseUrl != string.Empty)
            {
                Url = responseUrl;
            }
            if (htmlData != string.Empty)
            {
                string imageHtmlCode = "<img";
                string imageSrcCode  = @"src=""";
                int    index         = htmlData.IndexOf(imageHtmlCode);
                while (index != -1)
                {
                    htmlData = htmlData.Substring(index);
                    int brackedEnd = htmlData.IndexOf('>');
                    int start      = htmlData.IndexOf(imageSrcCode) + imageSrcCode.Length;
                    int end        = htmlData.IndexOf('"', start + 1);
                    if (end > start && start < brackedEnd)
                    {
                        string loc = htmlData.Substring(start, end - start);
                        imageList.Add(loc);
                    }
                    if (imageHtmlCode.Length < htmlData.Length)
                    {
                        index = htmlData.IndexOf(imageHtmlCode, imageHtmlCode.Length);
                    }
                    else
                    {
                        index = -1;
                    }
                }
                for (int i = 0; i < imageList.Count; i++)
                {
                    string img     = imageList[i];
                    string baseUrl = GetBaseURL(Url);
                    if ((!img.StartsWith("http://") && !img.StartsWith("https://")) &&
                        baseUrl != string.Empty)
                    {
                        img = baseUrl + "/" + img.TrimStart('/');
                    }
                    imageList[i] = img;
                }
            }
            return(imageList);
        }