1
私は次のコードでimdbを掻き集めようとしていました。simple_html_domライブラリのPHP正規表現
$url = "http://www.imdb.com/search/title?languages=en|1&explore=year";
$html = new simple_html_dom();
$html->load(str_replace(' ','',$data = get_data($url)));
foreach($html->find('#left') as $total_movies)
{
$content = $total_movies->plaintext;
if(preg_match("/(?<total>[0-9,]+) titles/",$content,$matches))
{
print_r($matches);
}
echo $content."<br>";
}
get_data()は作成したカール関数です。
問題は、preg_matchが機能していないことです。私は理由は分かっていませんが、ここで働くときは同じことがあります。 $ contentには、上記のコードでスクラップしたテキストが含まれています。
$content = "1-50 of 101 titles.";
if(preg_match("/(?<total>[0-9,]+) titles/",$content,$matches))
print_r($matches);
ありがとうございました。 – user1020363