我使用simple_html_dom
來獲取網站的圖片。但有時,圖片的鏈接沒有以完整的域URI作爲前綴,例如與http://example.com
。他們會出現像如何使用SimpleHTMLDom獲取絕對圖像的URIs
- 圖像/ _home-SS-21.jpg
- /_home-ss-22b.jpg
- ./_1249a7s.png或
- ../../。 ./a19489s_20110412.jpeg。
如何將這些URI轉換爲絕對URI,包括協議和域信息。
<?php
header('Content-type:text/html; charset=utf-8');
require_once 'simple_html_dom.php';
$v = 'http://www.typepad.com/';
$html = file_get_html($v);
foreach($html->find('img') as $element) {
echo $element->src.'<hr />';
}
?>
對不起,我已經測試了很長時間,但我已經解決了我的問題。你發現的一些文章可以很好地工作。再次感謝。 – 2011-04-13 13:48:35
!!!關於點擊第一個鏈接的重要警告。如果你點擊它,它會陷入你的頁面! – 2016-01-14 21:43:53