Sayfalar

Translate Blog

23 Ekim 2012 Salı

C# ile Firefoxtan Adresleri Almak / How to Capture Urls From Firefox


[ENG]
Maybe this code can help to obtain Firefox url adress; I use this code to capture uniq adresses from firefox and add to listbox. You can use this with safari too.
You must add NDde.dll to your project, To do this go to solution explorer rigth clik to References-> add Reference->Browse-> find that DLL (http://ndde.codeplex.com/ from binary folder.))

[TR]
Aşağıdaki kod C# kullanarak Firefox tarayıcısında girilen sayfaları listboxa ekler. Bunu timer aracılığı ile her 5sn de bir kontrol ederek yapıyor.
Kodları çalışması için NDde.dll isimli kütüphaneyi referanslarınıza eklemeniz lazım. http://ndde.codeplex.com/ adresinden kütüphaneyi indirin. Binary klasöründe Dll dosyasını bulacaksınız. C Sharp projenize gelin, Solution Explorer->References->Sağ Klik->Add Reference->Browse-> DLL dosyasını seçin ve ekleyin.
Sahnede 1 buton, 1 listbox ve 1 timer var.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NDde.Client;

namespace WindowsFormsApplication9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

        private string GetBrowserURL(string browser)
        {
            try
            {
                DdeClient dde = new DdeClient(browser, "WWW_GetWindowInfo");
                dde.Connect();
                string url = dde.Request("URL", int.MaxValue);
                string[] text = url.Split(new string[] { "\",\"" }, StringSplitOptions.RemoveEmptyEntries);
                dde.Disconnect();
                return text[0].Substring(1);
            }
            catch
            {
                return null;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            int j=0;
            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                if (listBox1.Items[i].ToString() == GetBrowserURL("Firefox"))
                {
                    break;
                }
                else
                {
                    j++;
                }
            }
            if (j == listBox1.Items.Count)
            {
                listBox1.Items.Add(GetBrowserURL("Firefox"));
            }
        }
    }
}

Hiç yorum yok:

Yorum Gönder

Yorumunuz