-1

ID名からdivの内容を取得しようとしています。

ここに私が取得しようとしているdivがあります: <div id="article-body"> ... </div>

ただし、これは別の外部 Web サイトにあるため、www または http:// などで呼び出す必要があります...

私はそれが可能であると確信しています。PHP、DOM、jQueryなどを使用する必要があるかどうかはわかりません..

このコードは数行で実行できるはずだと考えています。何が最善の方法なのかわからないだけです。ヒントやアイデアをありがとう。

更新:これは重複した質問であることが示唆されました。そうではない。以下の提案された重複した質問のコードを使用しましたが、機能しません。

エラーの 1 つを次に示します:警告: DOMDocument::loadHTML() [domdocument.loadhtml]: ID changeRegionForm already defined in Entity, line: 85 in /home/content/w/i/s/wisdom33/html/testing/getDivExternalWebsite 14行目の.php

コードへのリンクは次のとおりです: http://massmediamail.com/testing/getDivExternalWebsite.php

コードは次のとおりです。

<html>

<body>
<?
$doc = new DomDocument;

// We need to validate our document before refering to the id
$doc->validateOnParse = true;
$doc->loadHtml(file_get_contents('http://www.lifesitenews.com/news/second-madagascar-archbishop-criticizes-catholic-relief-services-full-trans'));

var_dump($doc->getElementById('article-body'));
?>
</body>
</html>
4

2 に答える 2

6

答えはhttp://simplehtmldom.sourceforge.net/にあります

そして、上記の URL からコードをダウンロードして適切な場所に配置し、正しくリンクすると、下部にあるこのコードは、私が上記で求めたものにぴったりと機能します。

<?php

// Note you must download the php files from the link above 
// and link to them on this line below. 
include_once('../simple_html_dom.php');

$html = file_get_html('http://www.lifesitenews.com/news/second-madagascar-archbishop-criticizes-catholic-relief-services-full-trans');
$elem = $html->find('div[id=article-body]', 0);
echo $elem;

?>
于 2013-09-10T00:21:54.410 に答える