delphi 关于html解析类的使用

gangrenxie 2015-07-03 11:02:55
我有如下代码,我想把里面的文字以及文字后的第一个链接取出来,然后放到数据库里面,看了网上很多的html解析类,还是不会使用,把html放上来,哪位朋友帮看看怎么把代码中的所有“时间节目表”以及第一个链接对应的取出来,入到数据库里,有懂的朋友指导一下。


<li label="其他,马拉松">06:00 马拉松陈盆滨挑战100 第94天 <a href="/zhibo/other/2015/0704malasong.htm" target="_blank">乐视直播</a> <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://ftx2.wanjiashe.com/game.php?sid=15&zhibo" target="_blank">真实NBA游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="阿根廷">06:00 阿根廷杯 河床 - 罗萨里奥中央 <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://www.188bifen.com/" target="_blank">比分直播</a>
<a href="http://zhongchao.wanjiashe.com/game.php?sid=3&zhibo" target="_blank">官方中超游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="美国">06:30 友谊赛 美国 - 危地马拉 <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://www.188bifen.com/" target="_blank">比分直播</a>
<a href="http://zhongchao.wanjiashe.com/game.php?sid=3&zhibo" target="_blank">官方中超游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="足球,美洲杯">07:30 <b>美洲杯季军赛 秘鲁 - 巴拉圭</b> <a href="/zhibo/zuqiu/2015/0704meizhoubei.htm" target="_blank">等待更新</a> <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://match.sports.sina.com.cn/livecast/g/live.php?id=127184&_version_=1.0" target="_blank">文字直播</a> <a href="http://www.188bifen.com/" target="_blank">比分直播</a>
<a href="http://zhongchao.wanjiashe.com/game.php?sid=3&zhibo" target="_blank">官方中超游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="足球,MLS">09:00 MLS 休斯敦迪纳摩 - 芝加哥火焰 <a href="/zhibo/zuqiu/2015/0704xiusidundinamovszhijiagehuoyan.htm" target="_blank">乐视直播</a> <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://www.188bifen.com/" target="_blank">比分直播</a>
<a href="http://zhongchao.wanjiashe.com/game.php?sid=3&zhibo" target="_blank">官方中超游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="其他">10:00 环青海湖自行车赛 <a href="/zhibo/other/2015/0704zixingche.htm" target="_blank">CCTV5直播</a> <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://ftx2.wanjiashe.com/game.php?sid=15&zhibo" target="_blank">真实NBA游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="其他,斯诺克">11:00 斯诺克澳大利亚公开赛半决赛 <a href="/zhibo/other/2015/0704sinuoke.htm" target="_blank">广东体育</a> <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://ftx2.wanjiashe.com/game.php?sid=15&zhibo" target="_blank">真实NBA游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="足球,MLS">11:00 MLS 西雅图海湾人 - 华盛顿特区联 <a href="/zhibo/zuqiu/2015/0704xiyatuhaiwanrenvshuashengduntequlian.htm" target="_blank">乐视直播</a> <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://www.188bifen.com/" target="_blank">比分直播</a>
<a href="http://zhongchao.wanjiashe.com/game.php?sid=3&zhibo" target="_blank">官方中超游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="其他,高尔夫">11:30 高尔夫锦湖轮胎女子公开赛 <a href="/zhibo/other/2015/0704gaoerfu3.htm" target="_blank">新浪直播</a> <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://ftx2.wanjiashe.com/game.php?sid=15&zhibo" target="_blank">真实NBA游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="其他,乒乓球">12:30 国际乒联巡回赛韩国站1/4决赛 <a href="/zhibo/other/2015/0704pinglian.htm" target="_blank">PPTV直播</a> <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://ftx2.wanjiashe.com/game.php?sid=15&zhibo" target="_blank">真实NBA游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="其他,斯诺克">12:32 斯诺克澳大利亚公开赛半决赛 <a href="/zhibo/other/2015/0704sinuoke2.htm" target="_blank">广东体育</a> <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://ftx2.wanjiashe.com/game.php?sid=15&zhibo" target="_blank">真实NBA游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="其他">12:35 世界夏季大学生运动会 <a href="/zhibo/other/2015/0704daxuesheng.htm" target="_blank">CCTV5直播</a> <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://ftx2.wanjiashe.com/game.php?sid=15&zhibo" target="_blank">真实NBA游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="游戏">13:00 LPL夏季赛 <a href="/zhibo/other/2015/0704lpl.htm" target="_blank">玩家社直播</a> <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://ftx2.wanjiashe.com/game.php?sid=15&zhibo" target="_blank">真实NBA游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>
<li label="其他,其他">13:15 谁是球王-青少年校园足球争霸赛 <a href="/zhibo/other/2015/0704xiaoyuan.htm" target="_blank">CCTV5直播</a> <a href="http://www.zhibo8.cc/shouji.htm" target="_blank">手机看直播</a> <a href="http://ftx2.wanjiashe.com/game.php?sid=15&zhibo" target="_blank">真实NBA游戏</a>
<a href="http://www.bobo.com/1000?m=parazhibo8&sss=boboshift" target="_blank">看美女直播秀</a></li>

我需要的内容是这样的
06:00 马拉松陈盆滨挑战100 第94天 /zhibo/other/2015/0704malasong.htm
06:00 阿根廷杯 河床 - 罗萨里奥中央 http://www.xxx.cc/shouji.htm

依此类推
...全文
665 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gangrenxie 2015-07-03
  • 打赏
  • 举报
回复
引用 1 楼 ksrsoft 的回复:
你是要解析网页,请提供网址 要是解析字符串,就按上图的字符串解析了
我需要把这个网址的直播列表弄下来。网址是 website:='http://'+'www'+'.zhibo8'+'.cc'
缘中人 2015-07-03
  • 打赏
  • 举报
回复
你是要解析网页,请提供网址 要是解析字符串,就按上图的字符串解析了
gangrenxie 2015-07-03
  • 打赏
  • 举报
回复
引用 3 楼 ksrsoft 的回复:
uses MSHTML; 放控件WebBrowser1
procedure TFrmZhibo8.Button1Click(Sender: TObject);
var
  surl: string;
  elmt: IHTMLEleMent;
  emtTitlebar, emtContent, emta: IHTMLEleMent;
  ecLeft, ecContent: IHTMLElementCollection;
  i, j: Integer;    
  sdt1, sdt2, sbname, sburl: string; 
begin
  surl := 'http://www.zhibo8.cc/';
  WebBrowser1.Navigate(surl);
  while (WebBrowser1.ReadyState <> READYSTATE_COMPLETE) or WebBrowser1.Busy do
  begin
    Application.ProcessMessages;
  end;
  elmt := (WebBrowser1.Document as IHTMLDocument3).getElementById('left');
  ecLeft := elmt.children as IHTMLElementCollection;
  for i := 0 to ecLeft.length - 1 do
  begin
    elmt := ecLeft.item(i, 0) as IHTMLEleMent;
    if elmt._className <> 'box' then
      Continue;
    emtTitlebar := ((elmt.children as IHTMLElementCollection).item(0, 0)) as IHTMLEleMent;
    emtTitlebar := ((emtTitlebar.children as IHTMLElementCollection).item(0, 0)) as IHTMLEleMent;

    sdt1 := emtTitlebar.title;
    sdt2 := emtTitlebar.outerText;
    Memo1.Lines.Add(sdt1);
    Memo1.Lines.Add(sdt2);
    //
    emtContent := ((elmt.children as IHTMLElementCollection).item(1, 0)) as IHTMLEleMent;
    emtContent := ((emtContent.children as IHTMLElementCollection).item(0, 0)) as IHTMLEleMent;
    ecContent := emtContent.children as IHTMLElementCollection;
    for j := 0 to ecContent.length - 1 do
    begin

      try
        elmt := ecContent.item(j, 0) as IHTMLEleMent;
        sbname := elmt.outerText;

        emta := ((elmt.children as IHTMLElementCollection).item(0, 0) as IHTMLEleMent);
        sbname := sbname.Remove(Pos(string(emta.innerText), sbname) - 1);
        sburl := emta.getAttribute('href', 0);

        Memo1.Lines.Add(sbname + #9 + sburl);
      except

      end;

    end;   
  end;
end;
完全OK了!太强了 !
缘中人 2015-07-03
  • 打赏
  • 举报
回复
uses MSHTML; 放控件WebBrowser1
procedure TFrmZhibo8.Button1Click(Sender: TObject);
var
  surl: string;
  elmt: IHTMLEleMent;
  emtTitlebar, emtContent, emta: IHTMLEleMent;
  ecLeft, ecContent: IHTMLElementCollection;
  i, j: Integer;    
  sdt1, sdt2, sbname, sburl: string; 
begin
  surl := 'http://www.zhibo8.cc/';
  WebBrowser1.Navigate(surl);
  while (WebBrowser1.ReadyState <> READYSTATE_COMPLETE) or WebBrowser1.Busy do
  begin
    Application.ProcessMessages;
  end;
  elmt := (WebBrowser1.Document as IHTMLDocument3).getElementById('left');
  ecLeft := elmt.children as IHTMLElementCollection;
  for i := 0 to ecLeft.length - 1 do
  begin
    elmt := ecLeft.item(i, 0) as IHTMLEleMent;
    if elmt._className <> 'box' then
      Continue;
    emtTitlebar := ((elmt.children as IHTMLElementCollection).item(0, 0)) as IHTMLEleMent;
    emtTitlebar := ((emtTitlebar.children as IHTMLElementCollection).item(0, 0)) as IHTMLEleMent;

    sdt1 := emtTitlebar.title;
    sdt2 := emtTitlebar.outerText;
    Memo1.Lines.Add(sdt1);
    Memo1.Lines.Add(sdt2);
    //
    emtContent := ((elmt.children as IHTMLElementCollection).item(1, 0)) as IHTMLEleMent;
    emtContent := ((emtContent.children as IHTMLElementCollection).item(0, 0)) as IHTMLEleMent;
    ecContent := emtContent.children as IHTMLElementCollection;
    for j := 0 to ecContent.length - 1 do
    begin

      try
        elmt := ecContent.item(j, 0) as IHTMLEleMent;
        sbname := elmt.outerText;

        emta := ((elmt.children as IHTMLElementCollection).item(0, 0) as IHTMLEleMent);
        sbname := sbname.Remove(Pos(string(emta.innerText), sbname) - 1);
        sburl := emta.getAttribute('href', 0);

        Memo1.Lines.Add(sbname + #9 + sburl);
      except

      end;

    end;   
  end;
end;

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧