抓取网站 URL 以获取图像的路径

发布于 2024-09-11 10:00:21 字数 1894 浏览 0 评论 0原文

我正在编写一个简单的 php 脚本,它将构建我的 Facebook 粉丝页面上的相册列表。

Facebook 好心地提供了 Graph API,它给了我一个很好的相册列表,但是它们不再提供默认相册图像的路径。

我想编写一个 PHP 脚本,通过 curl 加载相册 url,并以某种方式获取包含缩略图的表中第一张图像的路径。这将是具有“UIPhotoGrid_Image”类的第一个 img 标签的“src”值。

包含好东西的布局代码块如下所示:

<div id="album_container">
    <div class="UIPhotoGrid_Container UIPhotoGrid_DefaultPadding">
        <table class="UIPhotoGrid_Table" cellpadding="0" cellspacing="0">
            <tr>
                <td class="UIPhotoGrid_TableCell">
                    <a class="UIPhotoGrid_PhotoLink clearfix" href="http://www.facebook.com/photo.php?pid=5004658&amp;id=20785087272"><img class="UIPhotoGrid_Image img" src="http://photos-e.ak.fbcdn.net/hphotos-ak-snc4/hs080.snc4/35354_422883027272_20785087272_5004658_704231_s.jpg" onload="this.fb_loaded = true;" /></a>
                </td>
                <td class="UIPhotoGrid_TableCell">
                    <a class="UIPhotoGrid_PhotoLink clearfix" href="http://www.facebook.com/photo.php?pid=5004659&amp;id=20785087272"><img class="UIPhotoGrid_Image img" src="http://photos-c.ak.fbcdn.net/hphotos-ak-snc4/hs080.snc4/35354_422883032272_20785087272_5004659_6158094_s.jpg" onload="this.fb_loaded = true;" /></a>
                </td>
                <td class="UIPhotoGrid_TableCell">
                    <a class="UIPhotoGrid_PhotoLink clearfix" href="http://www.facebook.com/photo.php?pid=5004660&amp;id=20785087272"><img class="UIPhotoGrid_Image img" src="http://photos-f.ak.fbcdn.net/hphotos-ak-snc4/hs080.snc4/35354_422883037272_20785087272_5004660_1787119_s.jpg" onload="this.fb_loaded = true;" /></a>
                </td>
            </tr>
        </table>
    </div>
</div>

遗憾的是,这超出了我当前的编码能力......有什么想法吗?

I'm hacking together a simple php script that will build a list of photo albums I have on my Facebook fan page.

Facebook kindly offer the Graph API which gives me back a nice list of Albums, however they no longer provide the path of the default album image.

I want to write a PHP script that loads an album url via curl and somehow grab the path of the first image in the table that contains the thumbnails. This would be the "src" value of the first img tag that has a class of "UIPhotoGrid_Image".

The block of layout code that contains the good stuff looks like this:

<div id="album_container">
    <div class="UIPhotoGrid_Container UIPhotoGrid_DefaultPadding">
        <table class="UIPhotoGrid_Table" cellpadding="0" cellspacing="0">
            <tr>
                <td class="UIPhotoGrid_TableCell">
                    <a class="UIPhotoGrid_PhotoLink clearfix" href="http://www.facebook.com/photo.php?pid=5004658&id=20785087272"><img class="UIPhotoGrid_Image img" src="http://photos-e.ak.fbcdn.net/hphotos-ak-snc4/hs080.snc4/35354_422883027272_20785087272_5004658_704231_s.jpg" onload="this.fb_loaded = true;" /></a>
                </td>
                <td class="UIPhotoGrid_TableCell">
                    <a class="UIPhotoGrid_PhotoLink clearfix" href="http://www.facebook.com/photo.php?pid=5004659&id=20785087272"><img class="UIPhotoGrid_Image img" src="http://photos-c.ak.fbcdn.net/hphotos-ak-snc4/hs080.snc4/35354_422883032272_20785087272_5004659_6158094_s.jpg" onload="this.fb_loaded = true;" /></a>
                </td>
                <td class="UIPhotoGrid_TableCell">
                    <a class="UIPhotoGrid_PhotoLink clearfix" href="http://www.facebook.com/photo.php?pid=5004660&id=20785087272"><img class="UIPhotoGrid_Image img" src="http://photos-f.ak.fbcdn.net/hphotos-ak-snc4/hs080.snc4/35354_422883037272_20785087272_5004660_1787119_s.jpg" onload="this.fb_loaded = true;" /></a>
                </td>
            </tr>
        </table>
    </div>
</div>

This sadly, is beyond my current coding capabilities... Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

傲世九天 2024-09-18 10:00:21

您可以使用 phpsimpledom 使用 jQuery 样式语法来获取路径。

注意:Facebook 可能有多个图像集群,因此照片的 URL 可能会随着时间的推移而改变。

You could use phpsimpledom to grab the path using a jQuery style syntax.

Note: Facebook probably have several image clusters, so the URL to the photo may change over time.

夏夜暖风 2024-09-18 10:00:21

你有几种可能性:

1)优雅的一种,你从你的html样本中创建一个dom树并提取你的标签

2)不太优雅但高效,你可以使用正则表达式来提取该信息

You have several possibilities :

1) elegant one, you make a dom tree from your html sample and extract your tag

2) less elegant but efficient, you can use a regexp to extract that information

可可 2024-09-18 10:00:21

您可以将站点源代码拉入字符串中,

   $url = “http://www.foo.com”;
   $str = file_get_contents($url);

如果没有适合您需求的正则表达式,我只能说,在以前的经验中,我使用了大量条件语句并严重依赖 substr(),但这可能并不明智。

You can pull the site source into a string with

   $url = “http://www.foo.com”;
   $str = file_get_contents($url);

Without a regular expression that will suit your needs, I can only say that in previous experiences I have used lots of conditional statements and relied heavily on substr(), however this is likely not wise.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文