简体   繁体   English

如何获取页面的所有图像?

[英]how to fetch all images of a page?

i need two tools or scripts in php.... 我需要使用PHP中的两个工具或脚本。...

First i need a tool/php scriot that can fetch all the images of a given link of a page,so that i can store those images in my database for later on showing them as the link's thumbnail. 首先,我需要一个可以提取页面给定链接的所有图像的工具/ php脚本,以便可以将这些图像存储在数据库中,以便以后将它们显示为链接的缩略图。

Second i need a tool/php script that can fetch title,description and snapshot thumbnail of the given link of a page. 其次,我需要一个工具/ php脚本,可以获取页面给定链接的标题,描述和快照缩略图。

How can i do so?? 我该怎么办? Any tool or any php script ?? 任何工具或任何PHP脚本?

EDIT: I need something similar to Facebook's thing which you get when you tries to post a 'Link' on anyone's wall or so. 编辑:我需要类似于Facebook的东西,当您尝试在任何人的墙上张贴“链接”时,您会得到。

Maybe this tool is what you are looking for : http://simplehtmldom.sourceforge.net/ . 也许您正在寻找此工具: http : //simplehtmldom.sourceforge.net/ You have an example in the Quick Start to get all the images. 您在快速入门中有一个获取所有图像的示例。

Edit : Here is a tutorial if you want : http://net.tutsplus.com/tutorials/php/html-parsing-and-screen-scraping-with-the-simple-html-dom-library/ 编辑:如果需要,这里是一个教程: http : //net.tutsplus.com/tutorials/php/html-parsing-and-screen-scraping-with-the-simple-html-dom-library/

Another way to do it is to use the DOM and the classes included in PHP (doc : http://fr2.php.net/manual/en/book.dom.php ). 另一种方法是使用DOM和PHP中包含的类(doc: http : //fr2.php.net/manual/en/book.dom.php )。 And to fetch all the meta tags of your page you can do : 并获取页面的所有meta标签,您可以执行以下操作:

<?php
$doc = new DOMDocument();
$doc->loadHTML('you_page.php');

$metas = $doc->getElementsByTagName('meta');

foreach ($metas as $meta)
{
    //To get a specific attribute
    echo $meta->getAttribute('your_attribute');
}

You could go with the current trends and use Node: Scrape web pages in real time with Node.js 您可以顺应当前趋势,并使用Node.js通过Node.js实时抓取网页

Though if you're on Windows and Unix scares you it may be more trouble than it's worth. 虽然如果您在Windows和Unix上感到恐惧,那麻烦可能比其价值更大。

Justin 贾斯汀

++ for SimpleHtmlDom ++用于SimpleHtmlDom

$ret = $html->find('a, img'); 

and to get title ,etc, you can use the same refer to the manual, 并获得标题等,您可以使用相同的参考手册,

http://simplehtmldom.sourceforge.net/manual.htm http://simplehtmldom.sourceforge.net/manual.htm

facebook doent't display the screen shot of the website, but a image which it thinks is relevant. facebook不会显示该网站的屏幕快照,而是显示它认为相关的图像。 They also follow the opengraph protocol, 他们还遵循opengraph协议,

for example if your website has 例如,如果您的网站有

<meta property="og:image" content="http://ia.media-imdb.com/rock.jpg"/>

meta tag , then it will use that image as the thumbnail for the wall post/ status. meta标签,那么它将使用该图像作为墙贴/状态的缩略图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM