随机化用户代理GeckoFX

时间:2016-05-09 17:56:24

标签: vb.net vb.net-2010 gecko geckofx

有没有办法使用Gecko Browser随机化用户代理?我尝试在一个单独的线程上做,但我不能,因为Gecko必须在同一个线程上运行。

1 个答案:

答案 0 :(得分:0)

试试这个

创建新类Global.cs

  

公共类Globals       {           public static ArrayList Useragent = new ArrayList();

}

您的form1代码中的下一个

  

私有字符串GetUserAgent()           {

        Random Rnd = new Random();
        return Convert.ToString(Globals.Useragent[Rnd.Next(0, Globals.Useragent.Count)]);
    }

使用用户代理行加载文件

  

private void button2_Click(object sender,EventArgs e)           {               var OpenFile = new OpenFileDialog();               OpenFile.Filter =" * .txt | * .TXT&#34 ;;               OpenFile.ShowDialog();               if(OpenFile.FileName!="")               {                   Globals.Useragent.AddRange(File.ReadAllLines(OpenFile.FileName));

        }
        else
        {
            MessageBox.Show("Chooee Your User agent file");
        }
    }

======================

  

私有字符串GetUserAgent()           {

        Random Rnd = new Random();
        return Convert.ToString(Globals.Useragent[Rnd.Next(0, Globals.Useragent.Count)]);
    }

好的结束!

现在你可以这样做 - 输入你的新代码GetUserAgent();

  

private void button1_Click(object sender,EventArgs e)           {              CookieManager.RemoveAll();               Gecko.GeckoPreferences.User [" general.useragent.override"] = GetUserAgent();                   }