欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

CSS選擇器如何實(shí)現(xiàn)字段-創(chuàng)新互聯(lián)

這篇文章主要介紹CSS選擇器如何實(shí)現(xiàn)字段,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)公司成立于2013年,先為松北等服務(wù)建站,松北等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為松北企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。

根據(jù)上面所學(xué)的CSS基礎(chǔ)語(yǔ)法知識(shí),現(xiàn)在來(lái)實(shí)現(xiàn)字段的解析。首先還是解析標(biāo)題。打開(kāi)網(wǎng)頁(yè)開(kāi)發(fā)者工具,找到標(biāo)題所對(duì)應(yīng)的源代碼。

CSS選擇器如何實(shí)現(xiàn)字段

發(fā)現(xiàn)是在div class="entry-header"下面的h2節(jié)點(diǎn)中,于是打開(kāi)scrapy shell 進(jìn)行調(diào)試

CSS選擇器如何實(shí)現(xiàn)字段

但是我不想要<h2>這種標(biāo)簽該咋辦,這時(shí)候就要使用CSS選擇器中的偽類(lèi)方法。如下所示。

CSS選擇器如何實(shí)現(xiàn)字段

注意的是兩個(gè)冒號(hào)。使用CSS選擇器真的很方便。同理我用CSS實(shí)現(xiàn)字段解析。代碼如下

# -*- coding: utf-8 -*-  
import scrapy  
import re  
class JobboleSpider(scrapy.Spider):  
    name = 'jobbole'  
    allowed_domains = ['blog.jobbole.com']  
    start_urls = ['http://blog.jobbole.com/113549/']  
    def parse(self, response):  
        # title = response.xpath('//div[@class = "entry-header"]/h2/text()').extract()[0]  
        # create_date = response.xpath("//p[@class = 'entry-meta-hide-on-mobile']/text()").extract()[0].strip().replace("&middot;","").strip()  
        # praise_numbers = response.xpath("//span[contains(@class,'vote-post-up')]/h20/text()").extract()[0]  
        # fav_nums = response.xpath("//span[contains(@class,'bookmark-btn')]/text()").extract()[0]  
        # match_re = re.match(".*?(\d+).*",fav_nums)  
        # if match_re:  
        #     fav_nums = match_re.group(1)  
        # comment_nums = response.xpath("//a[@href='#article-comment']/span").extract()[0]  
        # match_re = re.match(".*?(\d+).*", comment_nums)  
        # if match_re:  
        #     comment_nums = match_re.group(1)  
        # content = response.xpath("//div[@class='entry']").extract()[0]  
#通過(guò)CSS選擇器提取字段  
        title = response.css(".entry-header h2::text").extract()[0]  
        create_date = response.css(".entry-meta-hide-on-mobile::text").extract()[0].strip().replace("&middot;","").strip()  
        praise_numbers = response.css(".vote-post-up h20::text").extract()[0]  
        fav_nums = response.css("span.bookmark-btn::text").extract()[0]  
        match_re = re.match(".*?(\d+).*", fav_nums)  
        if match_re:  
            fav_nums = match_re.group(1)  
        comment_nums = response.css("a[href='#article-comment'] span::text").extract()[0]  
        match_re = re.match(".*?(\d+).*", comment_nums)  
        if match_re:  
            comment_nums = match_re.group(1)  
        content = response.css("div.entry").extract()[0]  
        tags = response.css("p.entry-meta-hide-on-mobile a::text").extract()[0]  
        pass

CSS選擇器如何實(shí)現(xiàn)字段

以上是“CSS選擇器如何實(shí)現(xiàn)字段”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)站名稱:CSS選擇器如何實(shí)現(xiàn)字段-創(chuàng)新互聯(lián)
轉(zhuǎn)載來(lái)于:http://chinadenli.net/article26/cdghcg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)響應(yīng)式網(wǎng)站網(wǎng)站設(shè)計(jì)品牌網(wǎng)站設(shè)計(jì)面包屑導(dǎo)航用戶體驗(yàn)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作