从网页抓取特定信息

时间:2013-07-11 18:00:27

标签: php web-crawler

http://www.tibia.com/community/?subtopic=characters&name=Nikla

在此链接中,在角色个人资料的底部,有一个死亡列表。 我如何“收集”日期信息?我并不担心其余的事情,只是每次死亡的日期。

我将使用PHP文件来完成此操作。

我看过这篇文章:How do I make a simple crawler in PHP? 我只是不知道从哪里开始。

有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:2)

您可以使用像Simple HTML DOM Parser这样的DOM解析。从SourceForge下载存档,在脚本中安装文件include,然后使用它。

该网站有一个丑陋的表格布局,但你可以做这样的事情:

<强>代码:

<?php

include('simple_html_dom.php');
$html = file_get_html('http://www.tibia.com/community/?subtopic=characters&name=Nikla');
$count = 0; //counter variable
foreach($html->find('//*[@id="characters"]/div[5]/div/div/table[3]/tbody/tr['.
  $i.']') as $table) { //traverse through the table and get <td> content
   echo $table."<br/>";
   $count++;
}

?>

<强>输出:

Character Deaths
Jul 11 2013, 08:08:11 CEST  Killed at Level 36 by Cintyus and Seque Ladinho.
Jul 11 2013, 07:32:31 CEST  Killed at Level 36 by Drunk Noongah and Rea Per.
Jul 09 2013, 22:05:42 CEST  Killed at Level 35 by Evil Kris and Tensser.
Jun 29 2013, 20:25:27 CEST  Killed at Level 27 by Knight Abron.
Jun 27 2013, 07:31:33 CEST  Killed at Level 23 by Mysterioz Pandoria Knight.
Jun 14 2013, 23:52:14 CEST  Died at Level 16 by a rotworm.

这只是一个让你入门的例子。你可以修改它并获得你想要的东西。

希望这有帮助!

相关问题