保存使用casperjs抓取网页时获得的表格数据 [英] Saving table data obtained while scraping a webpage using casperjs

查看:118
本文介绍了保存使用casperjs抓取网页时获得的表格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个是保存使用casperjs抓取网页时获得的表数据的最佳方法?

Which would be the best method to save table data obtained while scraping a webpage using casperjs?


  1. 使用json对象序列化后将其存储为文件。

  1. Using a json object and store it as a file after serializing.

对php使用ajax请求,然后将其存储在mysql数据库中。

Using ajax request to php then storing it in a mysql db.


推荐答案

为简单起见,将CasperJS视为一种获取数据的方法。用另一种语言处理它。我会选择#1选项 - 以JSON格式获取数据,并将其保存到文件中以便以后再进行操作。

For simplicity sake, view CasperJS as a way to getting data & handle it after in another language. I would go for option #1 - get the data in JSON format, and save it to a file to do work on later.

为此,您可以使用文件系统API PhantomJS提供的。您还可以将其与 CasperJS的cli界面结合使用,以便将参数传递给脚本(例如,要写入的临时文件)。

To do this, you can use the File System API that PhantomJS provides. You can also couple this with CasperJS's cli interface to allow you to pass arguments into the script (a temporary file to write to for example).

处理所有这些的脚本如下所示:

Your script to handle all of this would look like:


  1. 在Linux系统上获取临时文件路径( mktemp )。

  2. 调用CasperJS脚本,将该临时文件路径作为参数传递。

  3. 获取数据,使用File System API将其写入该文件,然后退出。

  4. 读入文件,使用它(保存到数据库等),删除临时文件。

  1. Get temporary file path (mktemp on linux systems).
  2. Call your CasperJS script, passing in that temporary file path as an argument.
  3. Get your data, write it to that file using the File System API, and exit.
  4. Read in the file, do work with it (save to database, etc), remove the temporary file.

这篇关于保存使用casperjs抓取网页时获得的表格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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