2012-02-28 5 views
0

나는 간단한 html dom 또는 다른 긁는 질문이 있습니다. 심지어 파일을 파싱 할 수도 있습니다. 나는 모른다. 내가 여기에 행운과 함께 몇 가지 방법을 시도SimpleHTMLDom을 사용하여 웹 사이트에서 이미지 가져 오기

http://www.sierraavalanchecenter.org/bottomline-rss.php

// Include the library 
include('simple_html_dom.php'); 

$html = file_get_html('http://www.sierraavalanchecenter.org/bottomline-rss.php'); 

// Retrieve all images and print their SRCs 
foreach($html->find('img') as $e) 
    echo $e->src . '<br>'; 

// Find all images, print their text with the "<>" included 
foreach($html->find('img') as $e) 
    echo $e->outertext . '<br>'; 

// Find the DIV tag with an id of "myId" 
foreach($html->find('div#dangericon') as $e) 
    echo $e->innertext . '<br>'; 

: 나는

내가 시도하고이 피드에서 이미지를 얻기 위해 간단한 HTML 돔을 사용하고 ... 삼진 아웃입니다 . 위 코드는 http://davidwalsh.name/php-notifications입니다.

내가 잘못하고있는 것이 확실하지 않습니다. HR 태그와 같은 몇 가지 작은 물건을 얻을 수는 있지만 위험 장미는 아닙니다 .feedEntryContent->table->tbody->tr->td

이 두 가지를 모두 $ 변수에 넣어서 다른 레이아웃에서 사용할 수 있습니다.

아무쪼록 고맙습니다.

편집 : 이것은 위험 로즈입니다. bottom-line.php 파일에 뭔가있을 수 있습니다 ...?

<?php 
// Include the library 
include('simple_html_dom.php'); 

$html = file_get_html('http://www.sierraavalanchecenter.org/advisory'); 

foreach($html->find('td.views-field-field-danger-rose-php-value img') as $e){ 
     echo '<img src="http://www.sierraavalanchecenter.org/'. $e->src . '" width="400px" height="180px"/><br>'; 
} 
?> 
+0

simplexml_load_file 사용하여 구문 분석을 권 해드립니다 RegEx를 사용하고 싶지 않습니다. 감사. – jasonflaherty

답변

1

여기서 구문 분석하려는 파일은 xml 파일입니다.

나는 그것은 중복 원인이 아니다 당신이 (http://nz.php.net/manual/en/function.simplexml-load-file.php)

<?php 
include('simple_html_dom.php'); 

$xml = simplexml_load_file('http://www.sierraavalanchecenter.org/bottomline-rss.php'); 

$description = (string)$xml->channel->item->description; 

$html = new simple_html_dom(); 
$html->load($description); 

foreach($html->find('img') as $image) { 
echo $image->src . '<br/>'; 
} 
?> 
+0

안녕하세요, Tim 답장을 보내 주셔서 감사합니다. 파일의 내용이 올바른 형식의 XML 스타일이 아닙니다. 그것은 페이지처럼 보입니다 ...하지만 효과가있었습니다! 고마워. – jasonflaherty

+0

그물에있는 XML 파일은 거의 형성되지 않습니다.) simplexml은 꽤 튼튼합니다. – Tim

+0

XML이 잘 형성되지 않으면 simplexml에서 오류가 발생합니다. 그것은 doesnt한다. XML 파일이 유효합니다. 도움말 : – Gordon

관련 문제