0

如何正确抓取 HTML 文档中显示的图像并将其提供给 PHP 以作为图像二进制文件读取。我没有直接访问图像文件的权限。我试图抓取的图像通过 PHP 使用 HTML 提供给客户端,并以 HTML 格式打印,并使用<img>标签显示图像。src 只是指向我当前所在页面的链接。该链接是一个 GET 请求。

链接如下所示:

GETIMAGE.php?type=small&path=/path/to/image.png

这不会返回具有图像 MIME 类型的实际图像。而是显示图像的 HTML。

我无权访问 GETIMAGE.php 文件中的源代码。这是加密的,因为我使用的是获得许可的门户解决方案。

这是从 GETIMAGE.php 脚本返回的源代码:

<html>
<head>
    <meta name="viewport" content="width=device-width">
    <title>GETIMAGE.php (80×112)</title>
    <style type="text/css"></style>
</head>
<body style="margin: 0px;">
    <img style="-webkit-user-select: none" src="http://portal.craftnordic.com/PORTAL/GETIMAGE.php?type=small&amp;path=Path/To/Image.png">
</body>

4

3 回答 3

1

如果没有看到您的脚本,就很难弄清楚您在寻找什么。假设页面生成如下输出:

<img src="http://imgplacewhatever.com/lskjdflksdjf.png" />

使用这个优秀的DOM Parsing Library,我们可以做这样的事情:

$html = file_get_html('GETIMAGE.php?type=small&path=/path/to/image.png');
$pictures = array();
foreach($html->find('img') as $element) 
   $pictures[] = $element->src;
}

foreach ($pictures as $picture) {
   $data = file_get_contents($picture);
   ## Do something with the data.
}

然后,您将拥有一个包含所有图片的数组$pictures

祝你好运。

于 2013-11-06T14:30:45.557 回答
0

您可以使用 file_get_contents() 方法来获取数据。

在这里你可以使用

$filePath=$_GET['path'];
$imageData=file_get_contents($filePath);
于 2013-11-06T14:29:32.377 回答
0

不知道你有没有找到答案,但我终于找到了。file_get_contents 或任何 CURL 方法接收的数据实际上是以 gzip 格式返回的数据。当我将输出保存到文件并将其解压缩为 gzip 存档时,图像就在那里。

于 2014-10-21T19:53:00.853 回答