我们以站壳网(zhankr.net)来举例,当然这个你也可以自己做影视搜索来使用。
1、搜索接口
首先你要找到自己要搜索网站的接口。
所以,可以看出搜索接口:https://www.zhankr.net/?s=
2、网站搜索正则表达式
正则表达式教程:
任意内容替换为:(.*?)
我们取其中的一个DIV来看下他的链接,标题规则
<div class="ceo-width-1-1@s ceo-width-1-4@m ceo-width-1-4@l ceo-width-1-4@xl ceo-first-column">
<div class="card-item b-r-4 ceo-background-default ceo-overflow-hidden ceo-vip-icons">
<span class="meta-vip-tag"></span>
<div class="ceo_app_img">
<a href="https://www.zhankr.net/410910.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_blank" class="cover ceo-display-block ceo-overflow-hidden " style="height:180px">
<img src="https://zhankr.wogaoyun.com/2021/02/fa7f48443c04e69f16e7189d6151d817.png" alt="八月最新版白色微交易币圈mix匹块链源码【站长亲测】" class="ceo-width-1-1@s">
</a>
</div>
<div class="ceo-padding-remove">
<div class="card-title-desc">
<a href="https://www.zhankr.net/410910.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_blank" class="title ceo-display-block" title="八月最新版白色微交易币圈mix匹块链源码【站长亲测】">
八月最新版白色微交易币圈mix匹块链源码【站长亲测】 </a>
</div>
</div>
<div class="ceo_freepath_subtitle">
<!--分类-->
<div class="ceo_freepath_zhujiang">
<a href="https://www.zhankr.net/yuanma/zhifu" rel="external nofollow" ><i class="fa fa-folder-open-o ceo-right-3"></i>支付/金融/货币</a> </div>
<!--演示-->
<div class="ceo_freepath_keshi">
</div>
<!--标签-->
<div class="ceo_biaoqian">
</div>
</div>
<div class="ceo-padding-small card-foot ceo-card-foot">
<div class="item-foot ceo-flex ceo-flex-middle">
<div class="avatar ceo-flex-1 ceo-flex ceo-flex-middle">
<img alt="" src="//thirdqq.qlogo.cn/g?b=oidb&k=0HpGUbv0hIlXkFClkqa5yA&s=100&t=1583245434" class="avatar avatar-20 photo" data-id="1790" height="20" width="20"> </div>
<div class="cat ceo-font-mini ceo-text-truncate">
<span class="ceo-yc ceo-ycd ceo-display-inline-block ceo-flex ceo-flex-middle ceo-card-margin-left" ceo-tooltip="2021-02-14" title="" aria-expanded="false"><i class="iconfont icon-rili"></i> 6天前 </span>
<span class="ceo-ycd ceo-display-inline-block ceo-flex ceo-flex-middle ceo-card-margin-left"><i class="iconfont icon-yanjing"></i> 163 </span>
<span class="ceoshop-price ceo-card-margin-left" style="color: #ff4800;"><i class="iconfont icon-credit-level"></i> 0</span> </div>
</div>
</div>
</div>
</div>
从以上的代码可以看出链接和标题在这个<a>标签里面:
<a href="https://www.zhankr.net/410910.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_blank" class="title ceo-display-block" title="八月最新版白色微交易币圈mix匹块链源码【站长亲测】">
那它的正则写下来就是这样:
<a href="(.*?)" rel="external nofollow" (.*?)target="_blank"(.*?)class="title ceo-display-block"(.*?)title="(.*?)">
大家对比一下就清楚了,为了有些网站的代码书写不规范,我们可以将空格替换为(.*?)
3、网站标题,链接配置
通过上面的正则我们可以知道(.*?)
每个代表的什么意义,
比如站壳这个正则的标题就是第5个(.*?)
正则的链接就是第1个(.*?)
4、搜索返回数
如果你不填写,默认返回数为5,5就是最佳的数,数字过大会被屏蔽。