0

このStatsoft サイト、特にこの部分にhtml ファイルがあります。

<p>
    <a name="Z Distribution (Standard Normal)">
        <font color="#000080" size="4">
            Z Distribution (Standard Normal). 
        </font>
    </a>
    The Z distribution (or standard normal distribution) function is determined by the following formula:
</p>

テキストが必要で、次のThe Z distribution (or standard normal distribution) function is determined by the following formula:ようなコードをいくつか書きました。

include('simple_html_dom2.php');
$url = 'http://www.statsoft.com//textbook/statistics-glossary/z/?button=0#Z Distribution (Standard Normal)';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
$html = new simple_html_dom();
$html->load($curl_scraped_page);

foreach ($html->find('/p/a [size="4"]') as $e) {
    echo $e->innertext . '<br>';
}

それはちょうど私に与えました:Z Distribution (Standard Normal).

書いてみました

foreach ( $html->find('/p/a [size="4"]/font') as $e ) {

しかし、それは私に空白のページを与えました。

私は何を逃したのですか?ありがとうございました。

4

1 に答える 1

0

段落を見つけて、リンクからテキストを削除します。

include('simple_html_dom2.php');
$url = 'http://www.statsoft.com//textbook/statistics-glossary/z/?button=0#Z Distribution (Standard Normal)';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);

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

foreach ( $html->find('/p/a [size="4"]') as $font ) {
    $link = $font->parent();
    $paragraph = $link->parent();

    $text = str_replace($link->plaintext, '', $paragraph->plaintext);

    echo $text;
}

元の答え:

あなたの質問はこれに関連しています: 「Simple HTML DOM」を使用して2つのスパン間のテキストを取得する

セレクターはfontタグを見つけています。その親(aタグ)は、必要なテキストの兄弟です:

$text = $html->find('/p/a', 0)->next_sibling();
于 2013-06-25T03:03:32.843 に答える