private List <ProxyModel> updateProxyList()
        {
            List <ProxyModel> pl  = new List <ProxyModel>();
            HtmlWeb           web = new HtmlWeb();
            HtmlDocument      doc = web.Load("https://free-proxy-list.net/");
            var table             = doc.DocumentNode.SelectSingleNode("//table[@id='proxylisttable']");

            if (table != null)
            {
                var tbody = table.Descendants("tbody").FirstOrDefault();
                if (tbody != null)
                {
                    var rowList = tbody.Descendants("tr");
                    foreach (var tr in rowList)
                    {
                        var tdList = tr.Descendants("td").ToList();
                        if (tdList != null && tdList.Count() > 1)
                        {
                            string ip    = tdList[0].InnerText;
                            int    _port = 8080;

                            string port = tdList[1].InnerText;
                            int.TryParse(port, out _port);
                            ProxyModel p = new ProxyModel();
                            p.IP   = ip;
                            p.Port = _port;
                            pl.Add(p);
                        }
                    }
                }
            }
            return(pl);
        }
Exemple #2
0
        public static string getStringFromUrl(string Url)
        {
            string json = string.Empty;

            try
            {
                if (count < proxyList.Count())
                {
                    using (WebClient wc = new WebClient())
                    {
                        ProxyModel p        = proxyList[count];
                        WebProxy   webProxy = new WebProxy(p.IP, p.Port);

                        wc.Proxy = webProxy;
                        var str = wc.DownloadString(Url);

                        json = JObject.Parse(str).ToString();
                    }
                }
                else
                {
                    _updateProxyList();
                }
            }
            catch (Exception ex)

            {
                LoggerUtility.Write(ex.Message, Url);
                count++;
                if (count >= proxyList.Count)
                {
                    _updateProxyList();
                }

                LoggerUtility.Write("Changing IP to ", proxyList[count].IP);
                return(getStringFromUrl(Url));
            }
            return(json);
        }