【问题标题】:Get website information with regex and import it to listbox使用正则表达式获取网站信息并将其导入列表框
【发布时间】:2018-07-26 02:26:23
【问题描述】:

当我开始这个过程时,我进入了列表框“:”和 68,000 次点击 我从来没有使用过 WebRequest 这是第一次,所以我不知道。

我的正则表达式理论上很好,它可以恢复 2 个组,即 ip 和端口 除此之外,我还有一个问题,因为端口在后面的 2/5 位之间。这可能是个问题?因为 ip 是一组 2/3 位数字?

所以在我创建一个循环之后,它会恢复所有内容,并将结果放在 listbox1 中,方法是用“:”分隔 ip 和端口。

如果有人有答案!

谢谢。

【问题讨论】:

标签: c# io


【解决方案1】:
string Url = "https://www.us-proxy.org/";
        WebRequest wReq = WebRequest.Create(new Uri(Url));
        WebResponse wResp = wReq.GetResponse();
        StreamReader sr = new StreamReader(wResp.GetResponseStream());
        string str = sr.ReadToEnd();

        Regex Filtrer = new Regex("^([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}) ([0-9]{2,5})$");
        for (int i = 0; i < str.Length; i++)
        {
            Match matches = Filtrer.Match(str);
            listBox1.Items.Add(matches.Groups[1].Value +":"+ matches.Groups[2].Value);                
        }

【讨论】:

    【解决方案2】:

    更新

    string Url = "https://www.us-proxy.org/";
            WebRequest wReq = WebRequest.Create(new Uri(Url));
            WebResponse wResp = wReq.GetResponse();
            StreamReader sr = new StreamReader(wResp.GetResponseStream());
            string str = sr.ReadToEnd();
            string[] lines = str.Split('\n');
    
            Regex Filtrer = new Regex("^([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})([0-9]{2,5})$");
            for (int i = 0; i < lines.Length; i++)
            {               
                Match matches = Filtrer.Match(lines[i]);
                listBox1.Items.Add(matches.Groups[1].Value + ":" + matches.Groups[2].Value);
            }
    

    但是,我总是得到“:”是列表框。 我在列表框中有 7 个项目,但我尝试解析 url 中的 20 个项目。

    【讨论】:

      猜你喜欢
      • 2019-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      • 2014-03-31
      • 1970-01-01
      • 2023-04-04
      相关资源
      最近更新 更多