使用PHP爬取一个HTML页面? [英] crawling a html page using php?

查看:286
本文介绍了使用PHP爬取一个HTML页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个网站在一个列表中列出了超过250个课程。我想获得每门课程的名称并使用php将其插入到我的mysql数据库中。课程列举如下:

This website lists over 250 courses in one list. I want to get the name of each course and insert that into my mysql database using php. The courses are listed like this:

<td> computer science</td>
<td> media studeies</td>
…

有没有办法在PHP中做到这一点,而不是我疯了数据录入噩梦?

Is there a way to do that in PHP, instead of me having a mad data entry nightmare?

推荐答案

正则表达式正常运行。

$page = // get the page
$page = preg_split("/\n/", $page);
for ($text in $page) {
    $matches = array();
    preg_match("/^<td>(.*)<\/td>$/", $text, $matches);
    // insert $matches[1] into the database
}

请参阅 preg_match的文档

这篇关于使用PHP爬取一个HTML页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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