从源代码生成 Seletor,用于 scrapy

Generate Seletor from source code, for scrapy

我正在尝试从动态网页的源代码创建一个 CSS 选择器。我尝试过没有结果:

        response.css('seller-info#region *::text').get()
        response.css('seller-info > region *::text').get()
        response.css('.seller-info#region ::text').get()
        response.css('seller-info#region ::text').get()
        response.css('seller-info > region ::text').get()
        response.css('seller-info:contains("to extract")::text').get()
        response.css('.seller-info:contains("to extract")::text').get()
        response.css('.seller-info:contains("to extract") *::text').get()
        response.css('seller-info:contains("to extract") *::text').get()

每个人的回应:“None” 我需要文字:“提取” *地区名称在其他代码树中重复

源代码

<seller-info
    username='glorious'
    ispro='true'
    region="to extract"
    phoneurl='/pg/0.gif"'
    storeurl=""
    

    seniority=''
    category="1220"
    phonevisible='true'
>
   <div slot="avatar">
        
        
        
                <div class="seller-info__header--icon-container">
                    <i class="icon-yapo  icon-briefcase "></i>
                </div>
        
   </div>
</seller-info>```

您尝试从源代码中提取的数据 - 这是标签属性值(不是标签文本):

region = response.css("seller-info[region]::attr(region)").get()

或:

region = response.css("seller-info::attr(region)").get()

tagname::text 这样的选择器旨在提取
开始和结束标记之间的文本,例如 <tagname> text to extract </tagname>

您的 <seller-info> 标签 - 是自闭合标签(如 img 标签)。它将数据存储在其属性中。