cURLとPHPを使用して複数のURLを動的にフェッチしたい。単一のURLでこれを試してみると、機能しますが、複数のURLでは機能しません。助けてください。
私はURLを送信するためにフォームを使用しています:
$urls = $_POST["urls"];
require_once('simple_html_dom.php');
$useragent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
foreach ($urls as $url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
$str = curl_exec($curl);
curl_close($curl);
}
$html= str_get_html($str);
foreach($html->find('span.price') as $e)
echo $e->innertext . '<br>';