Anonymous
Anonymous

Reputation: 37

Scrapy Selecting Data Bind

How do I select a specific data bind element with scrapy?

                  <div class="col-sm-4">
                    <div data-bind="visible: (LotNumber > 0)">
                        <span class="carDetailLabel title" data-bind="text: ' ' + LotNumber"> 1</span>
                    </div>
                    <span data-bind="text: RegistrationNumber">VE16OML</span><br>
                    <span data-bind="text: Colour + ' ' + Transmission + ' ' + Fuel">Silver Manual Petrol</span><br>
                    <span data-bind="text: Doors + 'dr ' + VehicleType">5dr Hatchback</span><br>
                    <span data-bind="text: Odometer + ' ' + OdometerType">118699 miles</span><br>
                    <span data-bind="text: MileageWarranty">Not Warranted</span><br>
                    <span data-bind="text: MOTDateText">19/09/21</span><br>
                    <span data-bind="text: Grade">-</span>
                </div>

I want to select the odometer and MOTDateText databinds, but I'm unsure on how this would be written? I can currently print them all using:

from scrapy.spiders import Spider
from scrapy_splash import SplashRequest


class SpiderName(Spider):
    name = 'SpiderName'
    Page = 'https://www.urlname.com'

    def start_requests(self):
        yield SplashRequest(url=self.Page, callback=self.parse,
                            endpoint ='render.html',
                            args={'wait': 0.5},
                            )

    def parse(self, response):
        for x in response.css("div.row.list"):
            yield {
                'Entry': x.css("span[data-bind]::text").getall()

            }

How do I be specific with my selecting?

Thanks

Upvotes: 0

Views: 138

Answers (1)

stranac
stranac

Reputation: 28266

As far as scrapy is concerned, data-bind is not special, it behaves like any other attribute.

This means you can use any of the usual methods to match it, e.g.:

>>> x.css('span[data-bind="text: Odometer + \' \' + OdometerType"]::text').get()
'118699 miles'
>>> x.css('span[data-bind="text: MOTDateText"]::text').get()
'19/09/21'

Upvotes: 1

Related Questions