收集目标微信文章页标题、内容、发布时间、作者等信息。采集展示示例URLhttps://mp.weixin.qq.com/s?src=11×tamp=1523173327&ver=803&signature=6PCxJ*3ojH2ZM8pm56Lquward0mQMwSkPnqCvYlrDkQmL2kAEjGcFJMj2lzvpHyuyT30lczb2Ld0npUWmp*2Gj7bPJY3SCWrpRKlXJA0p4eQWPpAzMPJVmxPcRV5TtLS&new=1采集内容区图例分析内容选择器利用浏览器开发者工具来分析待采集的Areaselector,Iwon'texplainitindetailhere,ifyoudon'tunderstandit,请了解jQuery选择器和CSS选择器的相关知识,如图:分析结果:标题选择器为:.rich_media_title发布时间选择器为:#post-date作者选择器为:#meta_content>.rich_media_meta:eq(2)内容选择器为:.rich_media_content选择器的写法没有唯一性,只要内容选择器能被选中,想写什么就写什么。分析完codeselector,代码就很容易实现了。安装QueryListcomposerrequirejaeger/querylist微信采集码['.rich_media_title','text'],'date'=>['#post-date','text'],'author'=>['#meta_content>.rich_media_meta:eq(2)','text'],'content'=>['.rich_media_content','html']];$data=QueryList::get($url)->rules($rules)->query()->getData();print_r($data->all());可以轻松写出采集代码,看看运行结果:Array([0]=>Array([title]=>aè′???a????°?aa?èμ·????1???·2è¢???¤§?a????è?°?¨?¤?aèˉ′[日期]=>2018-04-08[作者]=>?èˉ?[内容]=>
......)内容按预期正确采集,但是内容是乱码解决乱码的方法有很多。QueryList内置的解决方案是使用encoding()和removeHead()。但是尝试过后发现当前场景没有任何效果,于是又用另外一种方法解决了微信乱码的问题,修改后的代码如下:['.rich_media_title','text'],'date'=>['#post-date','text'],'author'=>['#meta_content>.rich_media_meta:eq(2)','text'],'content'=>['.rich_media_content','html']];$html=GHttp::get($url);//直接匹配body中的内容preg_match('/]+>(.+)\s+<\/body>/s',$html,$arr);$html=$arr[0];$data=QueryList::html($html)->rules($rules)->query()->getData();print_r($data->all());运行结果:Array([0]=>Array([title]=>“贸易战”还没打响,特朗普又被各大媒体炮轰丨外媒称[日期]=>2018-04-08[作者]=>双语君[内容]=>
....)原文:http://study.querylist.cc/arc...