如何将html页面保存到数据库?

时间:2021-06-15 21:23:03

I just want to know if it's possible. How do I save an html page and all of its contents to a database? like for example, I have a database wherein it consists all HTML pages.

我只是想知道它是否可行。如何将html页面及其所有内容保存到数据库?例如,我有一个数据库,其中包含所有HTML页面。

Just want to know if its possible. And how to retrieve it too. We're using PHP as our language.

只是想知道它是否可能。以及如何检索它。我们使用PHP作为我们的语言。

Thank you.

6 个解决方案

#1


2  

Well, you'll need to:

好吧,你需要:

  • Grab that page by using a HTTP request, just like your browser does
  • 使用HTTP请求抓取该页面,就像您的浏览器一样

  • Parse that HTML to find external resources (script, img, object, etc)
  • 解析HTML以查找外部资源(脚本,img,对象等)

  • Grab those external resources
  • 抓住那些外部资源

  • Save all them on your database into a BLOB field
  • 将数据库中的所有数据保存到BLOB字段中

  • Optionally alter your original HTML document, to change that resources location
  • (可选)更改原始HTML文档,以更改该资源位置

#2


1  

Is this what you are trying to do? http://www.phpfreaks.com/forums/index.php?topic=219271.0 You can simply store the $out in the db instead of saving as html

这是你想要做的吗? http://www.phpfreaks.com/forums/index.php?topic=219271.0你可以简单地将$ out存储在db中而不是保存为html

#3


0  

Assuming MySQL, here is the way to connect to the database and write data into it.

假设MySQL,这里是连接数据库并将数据写入其中的方法。

PHP and MySQL

PHP和MySQL

#4


0  

HTML is just text. You can tore it in a database in a TEXT field.

HTML只是文字。您可以在TEXT字段中的数据库中将其撕碎。

There are plenty of DBMS you can use and plenty of ways to do it.

你可以使用大量的DBMS,并有很多方法可以做到这一点。

You can have a look at the PDO extension to directly consume a MySQL or SQlite connection for instance. You can also use an ORM like Doctrine

您可以查看PDO扩展以直接使用MySQL或SQlite连接。您也可以使用像Doctrine这样的ORM

#5


0  

If you are trying to save the final results of your PHP script (ie. what is sent to the browser) you will need to look into Output Buffering.

如果您尝试保存PHP脚本的最终结果(即发送到浏览器的内容),则需要查看输出缓冲。

#6


0  

As others already suggested, yes its possible to save HTML pages inside databases like mysql or sqlite etc. Another way you can perceive "databases" is flat files. Therefore, just like web crawlers or tools like wget/curl that crawls(and download) pages to disk, you can program something like that in PHP (using libraries such as curl) and save those pages to your disk. How to retrieve?? just display them with web browser OR do normal opening of file , display the contents and closing the file, all with PHP.

正如其他人已经建议的那样,是的,可以将HTML页面保存在mysql或sqlite等数据库中。另一种可以感知“数据库”的方法是平面文件。因此,就像网络抓取工具或像wget / curl这样将页面抓取(并下载)到磁盘的工具一样,您可以在PHP中编写类似的东西(使用诸如curl之类的库)并将这些页面保存到磁盘中。怎么检索?只需用网页浏览器显示它们或者正常打开文件,显示内容并关闭文件,全部用PHP。

#1


2  

Well, you'll need to:

好吧,你需要:

  • Grab that page by using a HTTP request, just like your browser does
  • 使用HTTP请求抓取该页面,就像您的浏览器一样

  • Parse that HTML to find external resources (script, img, object, etc)
  • 解析HTML以查找外部资源(脚本,img,对象等)

  • Grab those external resources
  • 抓住那些外部资源

  • Save all them on your database into a BLOB field
  • 将数据库中的所有数据保存到BLOB字段中

  • Optionally alter your original HTML document, to change that resources location
  • (可选)更改原始HTML文档,以更改该资源位置

#2


1  

Is this what you are trying to do? http://www.phpfreaks.com/forums/index.php?topic=219271.0 You can simply store the $out in the db instead of saving as html

这是你想要做的吗? http://www.phpfreaks.com/forums/index.php?topic=219271.0你可以简单地将$ out存储在db中而不是保存为html

#3


0  

Assuming MySQL, here is the way to connect to the database and write data into it.

假设MySQL,这里是连接数据库并将数据写入其中的方法。

PHP and MySQL

PHP和MySQL

#4


0  

HTML is just text. You can tore it in a database in a TEXT field.

HTML只是文字。您可以在TEXT字段中的数据库中将其撕碎。

There are plenty of DBMS you can use and plenty of ways to do it.

你可以使用大量的DBMS,并有很多方法可以做到这一点。

You can have a look at the PDO extension to directly consume a MySQL or SQlite connection for instance. You can also use an ORM like Doctrine

您可以查看PDO扩展以直接使用MySQL或SQlite连接。您也可以使用像Doctrine这样的ORM

#5


0  

If you are trying to save the final results of your PHP script (ie. what is sent to the browser) you will need to look into Output Buffering.

如果您尝试保存PHP脚本的最终结果(即发送到浏览器的内容),则需要查看输出缓冲。

#6


0  

As others already suggested, yes its possible to save HTML pages inside databases like mysql or sqlite etc. Another way you can perceive "databases" is flat files. Therefore, just like web crawlers or tools like wget/curl that crawls(and download) pages to disk, you can program something like that in PHP (using libraries such as curl) and save those pages to your disk. How to retrieve?? just display them with web browser OR do normal opening of file , display the contents and closing the file, all with PHP.

正如其他人已经建议的那样,是的,可以将HTML页面保存在mysql或sqlite等数据库中。另一种可以感知“数据库”的方法是平面文件。因此,就像网络抓取工具或像wget / curl这样将页面抓取(并下载)到磁盘的工具一样,您可以在PHP中编写类似的东西(使用诸如curl之类的库)并将这些页面保存到磁盘中。怎么检索?只需用网页浏览器显示它们或者正常打开文件,显示内容并关闭文件,全部用PHP。