-3
A
回答
1
這會幫助嗎?
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$html = file_get_contents_curl("http://example.com/");
//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
//get and display what you need:
$title = $nodes->item(0)->nodeValue;
$metas = $doc->getElementsByTagName('meta');
for ($i = 0; $i < $metas->length; $i++)
{
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'description')
$description = $meta->getAttribute('content');
if($meta->getAttribute('name') == 'keywords')
$keywords = $meta->getAttribute('content');
}
echo "Title: $title". '<br/><br/>';
echo "Description: $description". '<br/><br/>';
echo "Keywords: $keywords";
或者,如果您需要保存的圖像..
$remote_img = 'http://www.example.com/images/image.jpg ';
$img = imagecreatefromjpeg($remote_img);
$path = 'images/';
imagejpeg($img, $path);
function save_image($img,$fullpath){
$ch = curl_init ($img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec($ch);
curl_close ($ch);
if(file_exists($fullpath)){
unlink($fullpath);
}
$fp = fopen($fullpath,'x');
fwrite($fp, $rawdata);
fclose($fp);
}
+0
您可以將TagName更改爲任何您想要提取的數據 – themis 2012-08-13 00:29:43
相關問題
- 1. PHP提取HTML標記和內容
- 2. 內容中的HTML標記
- 3. 從目標中提取html標籤的字符串中提取內容
- 4. 從android的html內容中提取td和標題標籤?
- 5. 如何從HTML中提取內容
- 6. 獲取html標記之間的內容
- 7. python beautifulsoup獲取html標記內容
- 8. 如何使用javascript或jquery從字符串中提取html標記的內容?
- 9. 如何使用javascript或angularjs從字符串中提取html標記的內容?
- 10. 提取錨標記的內容
- 11. 獲取身體以外的所有內容html標記
- 12. Flowplayer RSS播放列表媒體:內容標記
- 13. 從html頁面提取內容
- 14. Atom提要可以包含媒體:內容標籤嗎?
- 15. 如何提取html標記標記
- 16. 獲取HTML內容提交
- 17. 從文件中獲取媒體標題
- 18. 解析元標記並從Tika身上獲取HTML內容
- 19. 從BeautifulSoup 4.6中的兩個HTML標記中提取HTML
- 20. 從標籤頁獲取HTML內容
- 21. 用PHP提取內容從標籤
- 22. 託管流媒體內容
- 23. 流媒體內容JSF UI
- 24. 獲取Javascript標記內容
- 25. xml中的多媒體內容
- 26. 禁用IE中的多媒體內容
- 27. 媒體查詢 - 中心內容
- 28. 從PHP中的HTML內容中提取數據
- 29. 正則表達式與具體內容匹配的HTML標記
- 30. 從兩個html標記中刪除內容
[*** *** SIGH(http://stackoverflow.com/search?q= [PHP] +解析+ html) – 2012-08-13 00:24:18
你有沒有想過自己想辦法呢?如果你甚至不能嘗試使用谷歌搜索,那麼你不應該停止這個網站。 – 2012-08-13 00:40:39