我有一个卷曲脚本,可以打电话和打印结果:
<div class="myClass">
<h3><a href="http://www.mysite.net/product-id" class="link " title="xxx">Title of link</a>
</h3>
</div>
PHP:
$ch = curl_init("mysite.net/xxx/xxx/xxx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt( $ch, CURLOPT_USERAGENT, ' Mozilla/5.0 (Windows NT 6.3; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0' );
$html = curl_exec($ch);
curl_close($ch);
echo $html;
页面自动必须仅打印此div之间的URL
最好的方法是怎样做的?的Javascript?
答案 0 :(得分:0)
你需要在php页面中使用pre_match
,例如
if ( preg_match("'<a.*?href=\"(http[s]*://[^>\"]*?)\"[^>]*?>(.*?)</a>'si",$html ,$m) )
{
echo "the link is =>".$m[1];
}
//or to get between <div class="myClass">
if ( preg_match('/<div class="myClass">(.*)<\/div>/is',$html,$m) )
{
echo "<br />found this =>".$m[1];
}