有人可以帮助我使用代理列表

时间:2012-08-26 06:21:18

标签: c#

好的,有人说要把我的代理放在一个列表中,这样我就可以为每个请求使用一个新的代理,我将代理保存到列表中,但是我对这里的去处感到有点困惑

这是我用来生成代理列表的代码,它来自proxies.txt文件。

    private List<string> getProxyListFromText(string input) {

        List<string> list = new List<string>();
        StreamReader reader = new StreamReader(input);
        string item = "";
        while (item != null)
        {
            item = reader.ReadLine();
            if (item != null)
            {
                list.Add(item);                


            }

        }
        reader.Close();          
        return list;



    }

这里是请求,每个请求都应该从列表中检索不同的代理。

图片循环遍历名称列表的for循环,每个名称都会显示不同的请求,每个请求都应该拥有自己的代理,代理列表已经在上面的代码中生成,只需要一种我可以检索的方式列表中的代理。

    for (int i = 0; i < listBox1.Items.Count; i++)
        {

    object url;
                    WebClient wc;
                    url = getppl;
                    wc = new WebClient();

                //This should come from the proxy list
                wc.Proxy = new WebProxy(getProxyListFromText("Proxies.txt"));

                    var page = wc.DownloadString(url.ToString());
                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(page);
                    var pplname = doc.DocumentNode.SelectNodes("/html/body/div[3]/div/div[2]/div[2]/div/div[4]/p");
     }

我尝试了一个嵌套的for循环但是逻辑被绑在了某个地方。

1 个答案:

答案 0 :(得分:0)

更改为: -

foreach(string prox in getProxyListFromText("Proxies.txt"))
{
 ...
 wc.Proxy = new WebProxy(prox);
 ...
}