Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c中从web中刮取数据并连接字段#_C#_Screen Scraping - Fatal编程技术网

C# 在c中从web中刮取数据并连接字段#

C# 在c中从web中刮取数据并连接字段#,c#,screen-scraping,C#,Screen Scraping,我正试图用C#为一个学校项目制作一个简单的电视频道指南。 我是通过观看youtube教程制作的: List<string> programasSPTV1 = new List<string>(); List<string> horasSPTV1 = new List<string>(); WebClient web = new WebClient(); String html = we

我正试图用C#为一个学校项目制作一个简单的电视频道指南。 我是通过观看youtube教程制作的:

        List<string> programasSPTV1 = new List<string>();
        List<string> horasSPTV1 = new List<string>();
        WebClient web = new WebClient();
        String html = web.DownloadString("http://www.tv.sapo.pt/programacao/detalhe/sport-tv-1");
        MatchCollection m1 = Regex.Matches(html, "<a href=\"#\" class=\"pinfo\">\\s*(.+?)\\s*</a>", RegexOptions.Singleline);
        MatchCollection m2 = Regex.Matches(html, "<p>\\s*(.+?)\\s*</p>", RegexOptions.Singleline);

            foreach(Match m in m1)
            {
                string programaSPTV1 = m.Groups[1].Value;
                programasSPTV1.Add(programaSPTV1);
            }
            foreach (Match m in m2)
            {
                string hora_programaSPTV1 = m.Groups[1].Value;
                horasSPTV1.Add(hora_programaSPTV1);
            }

            listBox1.DataSource = programasSPTV1 + horasSPTV1;
列表程序assptv1=新列表();
List horasSPTV1=新列表();
WebClient web=新的WebClient();
字符串html=web.DownloadString(“http://www.tv.sapo.pt/programacao/detalhe/sport-tv-1");
MatchCollection m1=Regex.Matches(html,“,RegexOptions.Singleline);
MatchCollection m2=Regex.Matches(html,“\\s*(.+?)\\s*

”,RegexOptions.Singleline); foreach(匹配m1中的m) { 字符串程序asptv1=m.Groups[1]。值; programaSPTV1.Add(programaSPTV1); } foreach(匹配m,单位为m2) { 字符串hora_programaSPTV1=m.Groups[1]。值; horasSPTV1.Add(hora_程序asptv1); } listBox1.DataSource=programasSPTV1+HorasPtv1;
最后一行不正确…:(

我真正需要的是把时间和程序放在同一个盒子里

差不多

17时45分:本菲卡机场

而不是17点45分在一个盒子里,本菲卡在另一个盒子里…:/


如何才能做到这一点?

假设两个列表中的计数相同,则以下内容应能满足您的需要:

listBox1.DataSource = programasSPTV1.Zip(horasSPTV1, (a,b) => (a + " : " + b)).ToList();

程序ASSPTv1和horasSPTV1中的项目数相同吗?我相信它们的大小相同!现在我收到此错误:S错误消息-已添加。请列出解决此问题的方法!D谢谢Maksim!