在c#中从web中抓取数据并连接字段
本文关键字:数据 连接 字段 抓取 中从 web | 更新日期: 2023-09-27 18:28:25
我正在尝试使用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;
最后一行不正确…:(
我真正需要的是把时间和程序放在同一个盒子里。。。
类似的东西
17时45分:本菲卡FCPorto
而不是17点45分在一个盒子里,本菲卡FCPorto在另一个盒子…:/
我该怎么做?
假设两个列表中的计数相同,那么以下内容应该会满足您的需求:
listBox1.DataSource = programasSPTV1.Zip(horasSPTV1, (a,b) => (a + " : " + b)).ToList();