解析外部网站表 [英] Parse external website table

查看:150
本文介绍了解析外部网站表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个日历: http://www.friendsbalt.org/upper /stulife/calendar.asp 以静态表的形式,我想要一个服务器抓取并逐行解析表。这可能吗?你会如何做到最有效的方式?

There is a calendar on: http://www.friendsbalt.org/upper/stulife/calendar.asp in the form of a static table, I want to have a server grab and parse out the table row by row. Is this possible? How would you do it the most efficient way possible? Code examples would be amazing.

推荐答案

您可以使用类似简单的HTML DOM ,如果您希望通过网页完成。

You could use something like Simple HTML DOM for php if you wanted it to be done by a web page.

require "simple_html_dom.php"; //Get this file from the link above
$html = file_get_html("http://example.com");
$data = array();
foreach($html->find("table tr") as $tr){
    $row = array();
    foreach($tr->find("td") as $td){
        /* enter code here */
        $row[] = $td->plaintext;
    }
    $data[] = $row;
}

然后所有的数据都将在$ data变量中。 >

Then all of the data will be in the $data variable.

var_dump($data); //To prove it works.

我会考虑将其放在刷新脚本中,并将所有信息保存到数据库。那么你可以从数据库中获取信息 - 这将几乎是即时的。

I would consider putting this in a 'refresh' script, and saving all the info to a database. Then you can just fetch the info from the database - which will be nearly instant.

然后,如果你想要的话,你可以制作一个cron脚本,让它运行一会儿本身 - 更新数据库,使其中的信息保持新鲜。

Then, if you wanted, you could make a cron script to make this run ever hour by itself - updating the database so that the information in it stays fresh.

这真的取决于你想要做什么:)

It really depends what you want to do with it :)

这篇关于解析外部网站表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆