当前位置: 首页 > 工具软件 > cheerio > 使用案例 >

cheerio根据多个class匹配

邓阳炎
2023-12-01
const cheerio = require('cheerio');
const $ = cheerio.load(`<div tbinfo="ouid=3215204864" action-type="feed_list_item" diss-data="" mid="3833324051403226" class="WB_cardwrap WB_feed_type S_bg2 WB_feed_like ">
                    <div class="WB_cardtitle_b S_line2">
            <h4 class="obj_name S_txt2">
                <span class="main_title"><i class="W_ficon ficon_praised S_ficon">ñ</i></span>
                <span class="subtitle"><a target="_blank" rel="noopener noreferrer" href="//weibo.com/2297899503/like?from=page_100606_profile&amp;wvr=6&amp;mod=like#status" suda-uatrack="key=tblog_profile_v6&amp;value=like_title">她2015-4-19赞过的微博</a></span>
            </h4>
        </div>
        <div class="WB_feed_detail clearfix" node-type="feed_content">
                        <div class="WB_screen W_fr" node-type="fl_screen_box">
    <div class="screen_box"><a href="javascript:void(0);" action-type="fl_menu"><i class="W_ficon ficon_arrow_down S_ficon">c</i></a>
        <div class="layer_menu_list" style="display: none; position: absolute; z-index: 999;" node-type="fl_menu_right">
            <ul>
                                                                                <li><a action-type="thrid_rend_iframe" href="javascript:void(0)" suda-data="" action-data="width=660&amp;height=556&amp;mid=3833324051403226&amp;src=%2F%2Fpromote.vip.weibo.com%2Fpromoteadvance%3Fdai_tou%3Dpc_profile_01%26touid%3D3215204864%26mid%3D3833324051403226&amp;title=推广" title="帮上头条">帮上头条</a></li>
                                                                                                                                                                    <li>
                                <span class="hover">
                                                                                                                        <a href="javascript:void(0);" onclick="javascript:window.open('https://service.account.weibo.com/reportspam?rid=CdYUt5T2G&amp;from=10106&amp;type=1&amp;url=%2Fthesecretapp&amp;bottomnav=1&amp;wvr=5', 'newwindow', 'height=700, width=550, toolbar =yes, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no');">投诉</a>
                                                                                                            </span>
                            </li>
                                                                        </ul>
        </div>
    </div>
</div>
        <div class="WB_face W_fl">
            <div class="face"><a target="_blank" class="W_face_radius" suda-uatrack="key=noload_singlepage&amp;value=user_pic" href="//weibo.com/ganliao?refer_flag=1005055013_" title="敢聊"><img usercard="id=3215204864&amp;type=0&amp;refer_flag=1005055013_" src="https://tva3.sinaimg.cn/crop.0.0.204.204.180/bfa42200jw8ergsuhh73wj205o05ogll.jpg?KID=imgbed,tva&amp;Expires=1579510206&amp;ssig=soJbTM4j96" width="50" height="50" alt="敢聊" class="W_face_radius"></a></div>
                                    <div class="opt" action-data="uid=3215204864&amp;fnick=敢聊&amp;f=1&amp;nogroup=1&amp;isrecommend=1&amp;special_focus=1&amp;template=3&amp;refer_from=single&amp;mark=&amp;refer_flag=1006060002_3215204864&amp;is_special=&amp;redirect_url=%2Fp%2F5299349643%2Fmyfollow%3Fgid%3D%23place" node-type="feed_recommend_follow"><a href="javascript:void(0)" node-type="feedfollow" data-mark="mark=" diss-data="refer_sort=feedad" action-type="follow" class="W_btn_b btn_22px"><em class="W_ficon ficon_add S_ficon">+</em>关注</a></div>
                    </div>

        <div class="WB_detail">
            <div class="WB_info">
                <a href="//weibo.com/ganliao?refer_flag=1005055013_" target="_blank" class="W_f14 W_fb S_txt1" usercard="id=3215204864&amp;type=0&amp;refer_flag=1005055013_" suda-uatrack="key=noload_singlepage&amp;value=user_name">敢聊</a>
                <a target="_blank" href="//fuwu.biz.weibo.com"><i title="微博官方认证" class="W_icon_co1 icon_approve_co"></i></a>                            </div>
            <div class="WB_from S_txt2">
                                <a name="3833324051403226" target="_blank" href="/3215204864/CdYUt5T2G?from=page_1006062297899503_profile&amp;wvr=6&amp;mod=weibotime" title="2015-04-19 12:52" date="1429419136000" class="S_txt2" node-type="feed_list_item_date" suda-data="key=tblog_home_new&amp;value=feed_time:3833324051403226:fromprofile"> 2015-4-19 12:52</a> 来自 <a class="S_txt2" suda-uatrack="key=profile_feed&amp;value=pubfrom_guest" action-type="app_source" target="_blank" href="https://app.weibo.com/t/feed/1tqBja" rel="nofollow">360安全浏览器</a>            \t            </div>

            <div class="PCD_user_b S_bg1" node-type="follow_recommend_box" style="display:none"></div>

            <div class="WB_text W_f14" node-type="feed_list_content" nick-name="敢聊">
                                                                                                                        <a target="_blank" render="ext" suda-uatrack="key=topic_click&amp;value=click_topic" class="a_topic" extra-data="type=topic" href="//s.weibo.com/weibo?q=%23%E8%B0%81%E7%89%B9%E4%B9%88%E8%AF%B44.19%E5%92%8C%E6%88%91%E6%B2%A1%E5%85%B3%E7%B3%BB%23&amp;from=default">#谁特么说4.19和我没关系#</a> 419究竟和谁有关?现在不再是约炮界的华山论剑,已经演化成了互联网的狂欢!谁是你心中主角?加入话题一起讨论!<a target="_blank" render="ext" extra-data="type=atname" href="//weibo.com/n/%E7%BE%8E%E4%B8%BD%E5%B1%8BAPP?from=feed&amp;loc=at" usercard="name=美丽屋APP">@美丽屋APP</a> <a target="_blank" render="ext" extra-data="type=atname" href="//weibo.com/n/G%E5%8F%8B%E5%90%8C%E5%BF%97%E4%BA%A4%E5%8F%8B?from=feed&amp;loc=at" usercard="name=G友同志交友">@G友同志交友</a> <a target="_blank" render="ext" extra-data="type=atname" href="//weibo.com/n/%E7%BB%B4%E9%94%90Fineck%E6%99%BA%E8%83%BD%E9%A2%88%E7%8E%AF?from=feed&amp;loc=at" usercard="name=维锐Fineck智能颈环">@维锐Fineck智能颈环</a> <a target="_blank" render="ext" extra-data="type=atname" href="//weibo.com/n/%E7%B3%96%E6%8A%A4%E5%A3%AB_%E7%B3%96%E5%B0%BF%E7%97%85%E4%B9%8B%E5%8F%8B?from=feed&amp;loc=at" usercard="name=糖护士_糖尿病之友">@糖护士_糖尿病之友</a> <a target="_blank" render="ext" extra-data="type=atname" href="//weibo.com/n/%E7%A7%98%E5%AF%86?from=feed&amp;loc=at" usercard="name=秘密">@秘密</a> <a target="_blank" render="ext" extra-data="type=atname" href="//weibo.com/n/%E6%95%A2%E8%81%8AApp?from=feed&amp;loc=at" usercard="name=敢聊App">@敢聊App</a> 等近100家app,高手云集,不怕你独领风骚,就怕你不敢一战!我们在这等着你! &#8203;&#8203;&#8203;&#8203;                                            </div>
                                                                <div class="WB_expand_media_box " style="display: none;" node-type="feed_list_media_disp"></div>
                                                                    <!-- 引用文件时,必须对midia_info赋值 -->
<!-- 微博心情,独立于标准的ul节点 -->
                    <div class="WB_media_wrap clearfix" node-type="feed_list_media_prev">
        <div class="media_box">
            <!--判断图片的个数,渲染图片-->
                            <!--图片个数大于1,不渲染卡片-->
                <!--TODO 只显示图片-->
                
\t\t\t\t     <!--picture_count == 7-->
    <ul class="WB_media_a WB_media_a_mn WB_media_a_m7 clearfix" node-type="fl_pic_list" action-data="isPrivate=0&amp;relation=0&amp;clear_picSrc=%2F%2Fww1.sinaimg.cn%2Fmw690%2Fbfa42200gw1erarsahl2nj212s13ithl.jpg,%2F%2Fww3.sinaimg.cn%2Fmw690%2Fbfa42200gw1erarsqm8m7j20c80g13zq.jpg,%2F%2Fww4.sinaimg.cn%2Fmw690%2Fbfa42200gw1erart6pxskj20c809ejrz.jpg,%2F%2Fww1.sinaimg.cn%2Fmw690%2Fbfa42200gw1erartet9y7j20f60brgoh.jpg,%2F%2Fww2.sinaimg.cn%2Fmw690%2Fbfa42200gw1erartpjc17j20c807amxh.jpg,%2F%2Fww1.sinaimg.cn%2Fmw690%2Fbfa42200gw1eraru50mauj20dg0nqabe.jpg,%2F%2Fww1.sinaimg.cn%2Fmw690%2Fbfa42200gw1erarudvbkrj20zk1jj7pm.jpg&amp;thumb_picSrc=%2F%2Fww1.sinaimg.cn%2Fthumb150%2Fbfa42200gw1erarsahl2nj212s13ithl.jpg,%2F%2Fww3.sinaimg.cn%2Fthumb150%2Fbfa42200gw1erarsqm8m7j20c80g13zq.jpg,%2F%2Fww4.sinaimg.cn%2Fthumb150%2Fbfa42200gw1erart6pxskj20c809ejrz.jpg,%2F%2Fww1.sinaimg.cn%2Fthumb150%2Fbfa42200gw1erartet9y7j20f60brgoh.jpg,%2F%2Fww2.sinaimg.cn%2Fthumb150%2Fbfa42200gw1erartpjc17j20c807amxh.jpg,%2F%2Fww1.sinaimg.cn%2Fthumb150%2Fbfa42200gw1eraru50mauj20dg0nqabe.jpg,%2F%2Fww1.sinaimg.cn%2Fthumb150%2Fbfa42200gw1erarudvbkrj20zk1jj7pm.jpg&amp;uid=3215204864&amp;pic_ids=bfa42200gw1erarsahl2nj212s13ithl,bfa42200gw1erarsqm8m7j20c80g13zq,bfa42200gw1erart6pxskj20c809ejrz,bfa42200gw1erartet9y7j20f60brgoh,bfa42200gw1erartpjc17j20c807amxh,bfa42200gw1eraru50mauj20dg0nqabe,bfa42200gw1erarudvbkrj20zk1jj7pm&amp;mid=3833324051403226&amp;pic_objects=&amp;object_ids=1042018%3A9f839312c55729ca7196b48cea350d48%2C1042018%3A83354c263e3496f6ae945a8d81c89f11%2C1042018%3Ab79f173eb0248c25b7d0a1e545f23545%2C1042018%3Aca11b82972a04a4092457464d9722e60%2C1042018%3A23d02a3dde1b59506ef17f396c05b6e1%2C1042018%3A10795350b67816901f171996a6162f3e%2C1042018%3A5d4161d104084c1861e66027a59a73c7&amp;photo_tag_pids=">
                                                    <li class="WB_pic li_1 S_bg1 S_line2 bigcursor " action-data="isPrivate=0&amp;relation=0&amp;pic_id=bfa42200gw1erarsahl2nj212s13ithl" action-type="fl_pics" suda-uatrack="key=tblog_newimage_feed&amp;value=image_feed_unfold:3833324051403226:bfa42200gw1erarsahl2nj212s13ithl:3215204864:0">
                               \t\t<img src="//ww1.sinaimg.cn/thumb150/bfa42200gw1erarsahl2nj212s13ithl.jpg">
         \t\t                                    </li>
                                                    <li class="WB_pic li_2 S_bg1 S_line2 bigcursor " action-data="isPrivate=0&amp;relation=0&amp;pic_id=bfa42200gw1erarsqm8m7j20c80g13zq" action-type="fl_pics" suda-uatrack="key=tblog_newimage_feed&amp;value=image_feed_unfold:3833324051403226:bfa42200gw1erarsqm8m7j20c80g13zq:3215204864:0">
                               \t\t<img src="//ww3.sinaimg.cn/thumb150/bfa42200gw1erarsqm8m7j20c80g13zq.jpg">
         \t\t                                    </li>
                                                    <li class="WB_pic li_3 S_bg1 S_line2 bigcursor " action-data="isPrivate=0&amp;relation=0&amp;pic_id=bfa42200gw1erart6pxskj20c809ejrz" action-type="fl_pics" suda-uatrack="key=tblog_newimage_feed&amp;value=image_feed_unfold:3833324051403226:bfa42200gw1erart6pxskj20c809ejrz:3215204864:0">
                               \t\t<img src="//ww4.sinaimg.cn/thumb150/bfa42200gw1erart6pxskj20c809ejrz.jpg">
         \t\t                                    </li>
                                                    <li class="WB_pic li_4 S_bg1 S_line2 bigcursor " action-data="isPrivate=0&amp;relation=0&amp;pic_id=bfa42200gw1erartet9y7j20f60brgoh" action-type="fl_pics" suda-uatrack="key=tblog_newimage_feed&amp;value=image_feed_unfold:3833324051403226:bfa42200gw1erartet9y7j20f60brgoh:3215204864:0">
                               \t\t<img src="//ww1.sinaimg.cn/thumb150/bfa42200gw1erartet9y7j20f60brgoh.jpg">
         \t\t                                    </li>
                                                    <li class="WB_pic li_5 S_bg1 S_line2 bigcursor " action-data="isPrivate=0&amp;relation=0&amp;pic_id=bfa42200gw1erartpjc17j20c807amxh" action-type="fl_pics" suda-uatrack="key=tblog_newimage_feed&amp;value=image_feed_unfold:3833324051403226:bfa42200gw1erartpjc17j20c807amxh:3215204864:0">
                               \t\t<img src="//ww2.sinaimg.cn/thumb150/bfa42200gw1erartpjc17j20c807amxh.jpg">
         \t\t                                    </li>
                                                    <li class="WB_pic li_6 S_bg1 S_line2 bigcursor " action-data="isPrivate=0&amp;relation=0&amp;pic_id=bfa42200gw1eraru50mauj20dg0nqabe" action-type="fl_pics" suda-uatrack="key=tblog_newimage_feed&amp;value=image_feed_unfold:3833324051403226:bfa42200gw1eraru50mauj20dg0nqabe:3215204864:0">
                               \t\t<img src="//ww1.sinaimg.cn/thumb150/bfa42200gw1eraru50mauj20dg0nqabe.jpg">
         \t\t                                    </li>
                                                    <li class="WB_pic li_7 S_bg1 S_line2 bigcursor " action-data="isPrivate=0&amp;relation=0&amp;pic_id=bfa42200gw1erarudvbkrj20zk1jj7pm" action-type="fl_pics" suda-uatrack="key=tblog_newimage_feed&amp;value=image_feed_unfold:3833324051403226:bfa42200gw1erarudvbkrj20zk1jj7pm:3215204864:0">
                               \t\t<img src="//ww1.sinaimg.cn/thumb150/bfa42200gw1erarudvbkrj20zk1jj7pm.jpg">
         \t\t                                    </li>
            </ul>
                    </div>
    </div>
        <!-- super card-->

                                                                                    <!-- feed区 大数据tag -->
                    </div>
        <div class="WB_like" node-type="templeLike_ani" action-data="parise_id=p_0000" style="display:none;">
            <div class="anibox UI_ani" style="background-image:url(//img.t.sinajs.cn/t6/skin/public/like/p_0000_pc.png?version=a97698e78db03400);"></div>
        </div>
    </div>
    <div class="WB_feed_handle" node-type="feed_list_options">
        <div class="WB_handle">
            <ul class="WB_row_line WB_row_r4 clearfix S_line2">
                                    <li>
                        <a class="S_txt2" suda-uatrack="key=profile_feed&amp;value=collect_guest" href="javascript:void(0);" diss-data="fuid=3215204864" action-type="fl_favorite"><span class="pos"><span class="line S_line1" node-type="favorite_btn_text"><span><em class="W_ficon ficon_favorite S_ficon">û</em><em>收藏</em></span></span></span></a>
                    </li>
                                                                            <li>
                            <a action-data="allowForward=1&amp;url=https://weibo.com/3215204864/CdYUt5T2G&amp;mid=3833324051403226&amp;name=敢聊&amp;uid=3215204864&amp;domain=ganliao&amp;pid=bfa42200gw1erarsahl2nj212s13ithl" action-type="fl_forward" action-history="rec=1" href="javascript:void(0);" class="S_txt2" suda-uatrack="key=profile_feed&amp;value=transfer"><span class="pos"><span class="line S_line1" node-type="forward_btn_text"><span><em class="W_ficon ficon_forward S_ficon"></em><em>62</em></span></span></span></a>
                            <span class="arrow"><span class="W_arrow_bor W_arrow_bor_t"><i class="S_line1"></i><em class="S_bg1_br"></em></span></span>
                        </li>
                                                    <li>
                                            <a href="javascript:void(0);" class="S_txt2" action-type="fl_comment" action-data="ouid=3215204864&amp;location=profile&amp;comment_type=0" suda-uatrack="key=profile_feed&amp;value=comment:3833324051403226"><span class="pos"><span class="line S_line1" node-type="comment_btn_text"><span><em class="W_ficon ficon_repeat S_ficon"></em><em>32</em></span></span></span></a>
                                        <span class="arrow"><span class="W_arrow_bor W_arrow_bor_t"><i class="S_line1"></i><em class="S_bg1_br"></em></span></span>
                </li>
                <li class="">
                    <!--cuslike用于前端判断是否显示个性赞,1:显示-->
                    <a href="javascript:void(0);" class="S_txt2" action-type="fl_like" action-data="version=mini&amp;qid=heart&amp;mid=3833324051403226&amp;loc=profile&amp;cuslike=1" title="赞" suda-uatrack="key=profile_feed&amp;value=like"><span class="pos"><span class="line S_line1">
                                                                                                                                                                                                                                                                            <span node-type="like_status" class=""><em class="W_ficon ficon_praised S_txt2">ñ</em><em>55</em></span>                        </span></span></a>
                    <span class="arrow" node-type="cmtarrow"><span class="W_arrow_bor W_arrow_bor_t"><i class="S_line1"></i><em class="S_bg1_br"></em></span></span>
                </li>
            </ul>
        </div>
    </div>
            <div node-type="feed_list_repeat" class="WB_feed_repeat S_bg1" style="display:none;"></div>
    </div>`);	
// 根据多个class来匹配
console.log($('div').attr('class', 'WB_cardwrap').attr('class', 'WB_feed_like').attr('mid'))

 

 类似资料: