-4

私はphpデータマイナー(スクレーパー)を構築しています。次のhtml行があります:

<label class='area'>
  <font class='bg_info' onmouseover="land_convert_txt(this,3067)" onmouseout='tooltip_hide()'>
   3,067 Sq. Ft.
  </font>

面積値のみを抽出するように正規表現をセットアップする方法は?

これは私の機能です:

function extract_regex($subject, $regex, $index = 1)
{
    preg_match_all($regex, $subject, $matches);
    if (count($matches[$index]))
    {
        if (count($matches[$index]) == 1)
        {
            return trim($matches[$index][0]);
        }
        return $matches[$index];        
    }
    return '';
}

(this,3067)変化し続ける!

よろしくお願いします

4

2 に答える 2

1

HTML の処理に正規表現を使用しないでください。
車輪を再発明しようとしないでください。おそらく正方形を作成します。

次のような PHP Web スクレイパーを使用してみてください。

http://net.tutsplus.com/tutorials/php/html-parsing-and-screen-scraping-with-the-simple-html-dom-library/

次のようなコードを使用します。

# create and load the HTML
include('simple_html_dom.php');
$html = new simple_html_dom();
$html->load($myHTML);

# get an element representing the area element
//$element =  $html->find('label[class=area]'); 
$element = $html->find(".area")

# Echo it out
echo $element[1]->innertext
于 2013-06-30T11:18:57.987 に答える