Maison > Article > développement back-end > 采撷正则 求大神解答
采集正则 求大神解答
<br /><h4 class="cat-hd fst-cat-hd "><br /> <br /> <i class="cat-icon fst-cat-icon active-trigger"></i><br /> <a class="cat-name fst-cat-name"<br /><br /> href="http://bosidengny.tmall.com/category-907362758.htm?search=y&catName=%D0%C2%C6%B7%D7%A8%C7%F8"<br /> >新品专区</a><br /> </h4><br /> </li><br /> <li class="cat fst-cat"><br /> <h4 class="cat-hd fst-cat-hd has-children"><br /> <br /> <i class="cat-icon fst-cat-icon active-trigger"></i><br /> <a class="cat-name fst-cat-name"<br /><br /> href="http://bosidengny.tmall.com/category-907362759.htm?search=y&catName=%B1%A3%C5%AF%C9%CF%D7%B0"<br /> >保暖上装</a><br /> </h4><br /> <div class="snd-pop"><br /> <div class="snd-pop-inner"><br /> <ul class="fst-cat-bd"><br /> <li class="cat snd-cat"><br /> <h4 class="cat-hd snd-cat-hd"><br /> <i class="cat-icon snd-cat-icon"></i><br /> <a class="cat-name snd-cat-name"<br /> href="http://bosidengny.tmall.com/category-907362760.htm?search=y&parentCatId=907362759&parentCatName=%B1%A3%C5%AF%C9%CF%D7%B0&catName=%BC%D9%C1%BD%BC%FE%A3%A8%B3%C4%C9%C0%C1%EC%A3%A9"<br /> ><br /> 假两件(衬衫领)<br /> </a><br /> </h4><br /> </li><br /> <li class="cat snd-cat"><br /> <h4 class="cat-hd snd-cat-hd"><br /> <i class="cat-icon snd-cat-icon"></i><br /> <a class="cat-name snd-cat-name"<br /> href="http://bosidengny.tmall.com/category-907362761.htm?search=y&parentCatId=907362759&parentCatName=%B1%A3%C5%AF%C9%CF%D7%B0&catName=V%C1%EC%C9%CF%D7%B0"<br /> ><br /> V领上装<br /> </a><br /> </h4><br /> </li><br />
$s =<<< TXT<br /><h4 class="cat-hd fst-cat-hd "><br /> <br /> <i class="cat-icon fst-cat-icon active-trigger"></i><br /> <a class="cat-name fst-cat-name"<br /> <br /> href="http://bosidengny.tmall.com/category-907362758.htm?search=y&catName=%D0%C2%C6%B7%D7%A8%C7%F8"<br /> >新品专区</a><br /> </h4><br /> </li><br /> <li class="cat fst-cat"><br /> <h4 class="cat-hd fst-cat-hd has-children"><br /> <br /> <i class="cat-icon fst-cat-icon active-trigger"></i><br /> <a class="cat-name fst-cat-name"<br /> <br /> href="http://bosidengny.tmall.com/category-907362759.htm?search=y&catName=%B1%A3%C5%AF%C9%CF%D7%B0"<br /> >保暖上装</a><br /> </h4><br /> <div class="snd-pop"><br /> <div class="snd-pop-inner"><br /> <ul class="fst-cat-bd"><br /> <li class="cat snd-cat"><br /> <h4 class="cat-hd snd-cat-hd"><br /> <i class="cat-icon snd-cat-icon"></i><br /> <a class="cat-name snd-cat-name"<br /> href="http://bosidengny.tmall.com/category-907362760.htm?search=y&parentCatId=907362759&parentCatName=%B1%A3%C5%AF%C9%CF%D7%B0&catName=%BC%D9%C1%BD%BC%FE%A3%A8%B3%C4%C9%C0%C1%EC%A3%A9"<br /> ><br /> 假两件(衬衫领)<br /> </a><br /> </h4><br /> </li><br /> <li class="cat snd-cat"><br /> <h4 class="cat-hd snd-cat-hd"><br /> <i class="cat-icon snd-cat-icon"></i><br /> <a class="cat-name snd-cat-name"<br /> href="http://bosidengny.tmall.com/category-907362761.htm?search=y&parentCatId=907362759&parentCatName=%B1%A3%C5%AF%C9%CF%D7%B0&catName=V%C1%EC%C9%CF%D7%B0"<br /> ><br /> V领上装<br /> </a><br /> </h4><br /> </li><br />TXT;<br /><br />include 'simple_html_dom.php';<br />$p = new simple_html_dom;<br />$p->load($s);<br />foreach($p->find('a') as $v) {<br /> echo $v->class, PHP_EOL; //这是可供区分级别的 class<br /> echo $v->href,PHP_EOL; //这是url<br /> echo trim($v->innertext()),PHP_EOL; //这是说明文字<br />}
cat-name fst-cat-name <br />http://bosidengny.tmall.com/category-907362758.htm?search=y&catName=%D0%C2%C6%B7%D7%A8%C7%F8<br />新品专区 <br />cat-name fst-cat-name<br />http://bosidengny.tmall.com/category-907362759.htm?search=y&catName=%B1%A3%C5%AF%C9%CF%D7%B0<br />保暖上装<br />cat-name snd-cat-name<br />http://bosidengny.tmall.com/category-907362760.htm?search=y&parentCatId=907362759&parentCatName=%B1%A3%C5%AF%C9%CF%D7%B0&catName=%BC%D9%C1%BD%BC%FE%A3%A8%B3%C4%C9%C0%C1%EC%A3%A9<br />假两件(衬衫领)<br />cat-name snd-cat-name<br />http://bosidengny.tmall.com/category-907362761.htm?search=y&parentCatId=907362759&parentCatName=%B1%A3%C5%AF%C9%CF%D7%B0&catName=V%C1%EC%C9%CF%D7%B0<br />V领上装<br />