3
A
回答
3
$content=file_get_contents($url);
if (preg_match("/<img.*src=\"(.*)\".*class=\".*pinit\".*>/", $content, $matches))
{
echo "Match was found <br />";
echo $matches[0];
}
$ matches [0]將打印整個圖像標籤。 如果你想只提取URL,那麼你可以使用$匹配[1]與您的情況下獲得相同的:)
+0
我試圖做同樣的「http://techcrunch.com/2014/05/09/facebook-is-down-for-many/」,但它不會返回任何東西。我知道位於這裏:但即使經過很少的改變它不會返回任何東西。任何幫助都會很好_/\ _ –
+0
該正則表達式對於特定網頁中的模式非常具體。 試試這個。 如果(的preg_match(「/
1
你可以/必須分析與DOM的HTML,這裏是例子:
$curlResource = curl_init('http://www.huffingtonpost.it/2013/07/03/stupri-piazza-tahrir-durante-proteste-anti-morsi_n_3538921.html?utm_hp_ref=italy');
curl_setopt($curlResource, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlResource, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curlResource, CURLOPT_AUTOREFERER, true);
$page = curl_exec($curlResource);
curl_close($curlResource);
$domDocument = new DOMDocument();
$domDocument->loadHTML($page);
$xpath = new DOMXPath($domDocument);
$urlXpath = $xpath->query("//img[@id='img_caption_3538921']/@src");
$url = $urlXpath->item(0)->nodeValue;
echo $url;
花點時間學習一點DOM和XPATH是值得的。
1
嘗試......
$content=file_get_contents($url);
if (preg_match("/src=[\"\'][^\'\']+[\"\']/", $content, $matches))
{
echo "Match was found <br />";
echo $matches[0];
}
相關問題
- 1. 使用php從html頁面提取href
- 2. Python:如何使用BeautifulSoup從HTML頁面中提取URL?
- 3. 使用PHP從.pdf中提取頁面
- 4. 使用PHP的DOM提取頁面的HTML使用PHP的DOM
- 5. 無法提取任何Facebook頁面圖像使用php
- 6. 使用PHP從SWF中提取圖像
- 7. 試圖從一個HTML頁面提取信息與PHP
- 8. 使用jQuery從頁面抓取圖像
- 9. 從PHP頁面中提取HTML代碼以推斷一些圖像
- 10. 如何使用PHP從Amazon.com頁面獲取圖像和數據?
- 11. 使用Perl從url中提取HTML
- 12. 從html頁面獲取URL - objective
- 13. 如何在html頁面中使用數據url顯示圖像
- 14. 從UIWebView中的頁面提取源URL
- 15. 從整個URL中提取jsp頁面
- 16. 如何從Python中的HTML頁面中提取URL
- 17. 只使用sed或awk從html頁面中提取url最簡單的方法
- 18. 使用PHP從數據中提取URL
- 19. 用Python從HTML頁面中提取圖片
- 20. 只從html頁面提取單詞
- 21. 從HTML頁面提取csv數據
- 22. sed從html頁面提取鏈接
- 23. 從html頁面提取classes/id
- 24. 從html頁面提取類內容
- 25. 從HTML頁面提取段落
- 26. 如何從HTML頁面提取鏈接?
- 27. 從HTML頁面提取數據(Python)
- 28. 如何從html頁面提取文本?
- 29. 從html頁面提取內容
- 30. 如何從html頁面提取文本?
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 –
感謝,那我該怎麼辦? – michele