中间会有代码,包括DIV,script等
1 个正则表达式怎么够。。。
根据左侧 srcid 分成 3 大分类,我用了 6 个正则表达式判断。
preg_match_all("/(?<=<div class\=\"result c\-container\" id\=\")(\d{1,2})(\" srcid\=\")(\d{1,5})(?=\" tpl\=\")/", $baiduserp, $matchsrcid)
preg_match_all("/(?<=<div class\=\"result\-op c\-container result\-zxl\" srcid\=\")(\d{1,5})(\" fk=\")(\d{0,5})(_?)([\.\d\w]+)(\" id\=\"zxl_)(\d{1,2})(?=\" tpl=\")/", $baiduserp, $matchzxl)
preg_match_all("/(?<=\" srcid\=\")(\d{1,5})(\" fk=\")(\d{0,5})(_?)(.+)(\" id\=\")(\d{1,2})(?=\" tpl\=\")/", $baiduserp, $matchfk)
preg_match("/(?<=\" srcid=\")(\d{1,5})(\" fk=\"\" id=\")(\d{1,2})(?=\" )/", $baiduserp, $matchAPP)
preg_match_all("/(?<=\" srcid\=\")(\d{1,5})(.+)(id\=\"zxl_)(\d{1,2})(?=\" tpl\=\")/", $baiduserp, $matchzxlrt)
preg_match_all("/(?<=\" srcid\=\")(\d{1,5})(\" id\=\")(\d{1,2})(?=\" tpl\=\")/", $baiduserp, $matchsp)
![](https://www.vm7.com/uploads/allimg/200303/f7d428dcc0deae8ef7640d49c21e780a.jpg)
###
这个不用正则那么麻烦,且效率不高。
直接使用dom解析方式获取更方便准确
jquery 可以,无需正则表达式
本文来自投稿,不代表微盟圈立场,如若转载,请注明出处:https://www.vm7.com/a/ask/24071.html