我需要为指定的关键字解析Google Images并检索图像链接,这可以使用PHP简单的dom解析器来完成,并且每次调用都可以检索一些图像链接。Google Images API目前被限制为100个调用。现在,我需要将这些图像链接保存为“关键字”,以便下次当我需要该关键字的图像时,我的脚本首先查找关键字及其相关图像(即URL)是否已经存储在我的系统中,以及是否需要调用Google。
存储该关键字和图像(即数据库或简单文本文件)的最有效方法是什么?
如果它是mySQL,那么它的模式是什么?
是否可以将图像链接存储在文件名为keyword的文本文件中?
发布于 2015-07-31 02:52:10
我建议使用mysql,选择它会给你带来灵活性,速度和轻松访问你的数据。只需将有关图像的信息放在一个表中,如下所示:
id | name | keyword | path | creTime | size | ext ( and any other that u would need )然后你就可以通过关键词拉取任意数量的图片,比如“水”、“视图”等等。
我可能会创建两个表,更改keywordId的关键字。然后创建Keyword_data的外键。现在您有了从Images_data到多个( id ) keyword_data的关系1( keywordId )。
id | keyword | description | ( anything else)这样你可以有多个关键字的任何图像组,因为它将更灵活。
发布于 2015-07-31 03:00:06
我通常喜欢使用关系数据库,因为随着您的成长,您可以使用它们做更多的事情。我还会向您的数据添加时间戳(如下所示),这样您就可以知道您的链接何时被缓存(因为这实际上就是您正在做的事情)。以下是我将使用的模式:
图片表
id - Integer, primary index, autoincrement
keyword - Varchar(50), indexed
url - Varchar(2083)
created_at - Timestamp
updated_at - Timestamp
Any other data you want to store, like image type, size, etc.URL的长度是based off of this post。
如果你想进一步规范化你的数据,你可以这样做:
图片表
id - Integer, primary index, autoincrement
keyword_id - integer, indexed
url - Varchar(2083)
created_at - Timestamp
updated_at - Timestamp
Any other data you want to store, like image type, size, etc.关键词
id - Integer, primary index, autoincrement
word - Varchar(50)
created_at - Timestamp
updated_at Timestamp
Any other data you want to store就我个人而言,我可能会选择第一个选项,因为它更简单(取决于您的数据将会有多大)。
https://stackoverflow.com/questions/31731671
复制相似问题