2012-02-28 21 views
0

私は単純なhtml domまたはその他の擦れ質問を持っています。ファイルを解析することさえできます。知りません。私はここにいない運でいくつかの異なる方法を試してみましたSimpleHTMLDomを使用してWebサイトから画像を取得する

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 DOMを使用しています...三振しています。上のコードは http://davidwalsh.name/php-notificationsから直接です。

私が間違っていることはわかりません。私はHRタグのような小さなものをもう一度入手しますが、Danger Roseは.feedEntryContent->table->tbody->tr->tdにあります。.feedEntryContent->table->tbody->tr->td

これらを両方とも$変数に入れて、別のレイアウトで使用できるようにしたいと思います。

ありがとうございました。

編集:これはDanger Roseを得ました。 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

を使用して、それを解析お勧めします私はRegExを使いたくない。ありがとう。 – jasonflaherty

答えて

1

ここで解析しようとしているファイルはxmlファイルです。

私はそれが重複の原因ではありませんあなたはsimplexml_load_file (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

こんにちはティム、返信いただきありがとうございます。ファイルの内容が整形式のXMLスタイルではありません。それはちょうどページのように見える...しかしそれは働いた!ありがとう。 – jasonflaherty

+0

ネット上のXMLファイルはほとんど形成されていません;)simplexmlはかなり頑丈です – Tim

+0

XMLがうまく形成されなかった場合、simplexmlはエラーを返します。それdoesnt。 XMLファイルは有効です。助けのための君たち 感謝:)あなたのプロフィールPICからだ – Gordon

関連する問題