如何在同一个打开的标签上打开新网址?

时间:2012-03-17 13:39:24

标签: c# web-crawler

我使用此代码以便从特定URL打开所有链接,每个链接都会打开新标签,这会导致巨大的内存使用,我如何在现有标签上打开新链接?

static void Main(string[] args)
{
    ProcessStartInfo processStartInfo = null;
    string googleChoromePath = "C:\\Users\\Dandin\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";
    string argument = "";
    string url = "http://edition.cnn.com/";
    WebClient wClient = new WebClient();
    string st = wClient.DownloadString(url);
    List<string> list = LinkFinder.Find(st);
    processStartInfo = new ProcessStartInfo(googleChoromePath);

    for (int i = 0; i < list.Count; i++)
    {
        argument = list[i];

        try
        {
            if (argument.StartsWith("http://"))
            {
                processStartInfo.Arguments = argument;
                processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.RedirectStandardError = true;
                processStartInfo.CreateNoWindow = true;
                processStartInfo.UseShellExecute = false;
                processStartInfo.ErrorDialog = false;

                Process googleChrome = Process.Start(processStartInfo);
                Thread.Sleep(1000);
            }
        }
        catch (Exception)
        {

        }
    }
}

0 个答案:

没有答案