我已经设法使用
HTMLDomParser(
http://simplehtmldom.sourceforge.net/)从网站获取一些HTML:
$html = HtmlDomParser::file_get_html('https://example.com/id=1');
这导致以下HTML:
<p> ANDE 2,the Atmospheric Neutral Density Experiment 2,is a pair of microsatellites (Castor and Pollux) launched from Cape Canaveral on STS 127 on 15 July 2009 at 22:03 UT and deployed from the payload bay of the shuttle on 30 July 2009 at 17:22 UT.</p> <p><strong>Launch Date:</strong> 2009-07-15<br/><strong>Launch Vehicle:</strong> Shuttle<br/><strong>Launch Site:</strong> Cape Canaveral,United States<br/></p>
我想要尝试做的是获取此HTML并将其保存到MysqL数据库.所以,在数据库中我将有四列:
>描述
>发布日期
>运载火箭
>启动网站
HTML布局将始终保持不变.我的其他数据库包含URL的ID.我能够用变量替换id = 1,因此我可以设法保存多个网页数据.
如果id不存在,我唯一担心的是.如果它找不到它正在寻找的HTML,是否可以跳过该页面?
我以前从未这样做过,所以我有点不知所措.甚至可以做到这一点吗?
基本上,我只想将DomParser中的数据保存到我的数据库中.
编辑:由于没有答案,我认为我们需要系统地解决这个问题 – 首先我们应该尝试创建将数据保存到数据库的功能.
编辑2:我只是想 – 也许需要保存HTML的函数可以通过标签(‘strong’,’p’等)从HTMLDomParser中分割结果,并为每列创建一个变量然后保存它.我想这里的问题首先是如何拆分HTML?
编辑3:由于我没有收到任何答案/建议,我猜测实现这一点非常复杂.我仍然没有设法将HTML成功保存到我的数据库.