原始碼是:
<code><a class="figure figure-180236 " data-qidanadd-albumid="543438400" data-qidanadd-episode="0" data-qidanadd-channelid="1" data-qidanadd-tvid="543438400" data-qidanadd-vip="0" data-widget-qidanadd="qidanadd" data-widget-block="block" data-block-type="qs1404043" data-searchpingback-elem="link" data-searchpingback-param="ptype=1-1" href="http://www.iqiyi.com/v_19rr9g9wks.html?fc=87451bff3f7d2f4a#vfrm=2-3-0-1" data-playsrc-linktype="play" data-playsrc-elem="pic" data-pb="rtgt=iqiyi&p2=9000" target="_blank"></code>
採集php程式碼是:
<code>preg_match("#<a class=\"figure figure-180236 \" data-qidanadd-albumid=\"543438400\" data-qidanadd-episode=\"0\" data-qidanadd-channelid=\"1\" data-qidanadd-tvid=\"543438400\" data-qidanadd-vip=\"0\" data-widget-qidanadd=\"qidanadd\" data-widget-block=\"block\" data-block-type=\"qs1404043\" data-searchpingback-elem=\"link\" data-searchpingback-param=\"ptype=1-1\" href=\"(.*?)\" data-playsrc-linktype=\"play\" data-playsrc-elem=\"pic\" data-pb=\"rtgt=iqiyi&p2=9000\" target=\"_blank\">#",$content,$array);</code>
但是這樣的話採集不到資訊?求解
原始碼是:
<code><a class="figure figure-180236 " data-qidanadd-albumid="543438400" data-qidanadd-episode="0" data-qidanadd-channelid="1" data-qidanadd-tvid="543438400" data-qidanadd-vip="0" data-widget-qidanadd="qidanadd" data-widget-block="block" data-block-type="qs1404043" data-searchpingback-elem="link" data-searchpingback-param="ptype=1-1" href="http://www.iqiyi.com/v_19rr9g9wks.html?fc=87451bff3f7d2f4a#vfrm=2-3-0-1" data-playsrc-linktype="play" data-playsrc-elem="pic" data-pb="rtgt=iqiyi&p2=9000" target="_blank"></code>
採集php程式碼是:
<code>preg_match("#<a class=\"figure figure-180236 \" data-qidanadd-albumid=\"543438400\" data-qidanadd-episode=\"0\" data-qidanadd-channelid=\"1\" data-qidanadd-tvid=\"543438400\" data-qidanadd-vip=\"0\" data-widget-qidanadd=\"qidanadd\" data-widget-block=\"block\" data-block-type=\"qs1404043\" data-searchpingback-elem=\"link\" data-searchpingback-param=\"ptype=1-1\" href=\"(.*?)\" data-playsrc-linktype=\"play\" data-playsrc-elem=\"pic\" data-pb=\"rtgt=iqiyi&p2=9000\" target=\"_blank\">#",$content,$array);</code>
但是這樣的話採集不到資訊?求解
請好好學習PHP的正規表示式模式,其中有一個m是指多行匹配可以滿足你的需求,http://php.net/manual/en/refe...。
建議html解析使用DiDom
類似jquery的dom選擇
說到底就是想得到超連結的href連結地址對吧,你的正則寫的太多了,寫的越多越難匹配到,另外多行匹配就像樓上說的有專門的模式匹配符,我一般用的是s