parik
parik

Reputation: 2415

What is equivalent of value_of_css_property in Scrapy using Selector?

for getting background from this tag

<body style="background-image: url(&quot;http://www.auchandrive.fr/drive/static-media/public2/zones_edit/bannieres/_2016/S49/background_festif2016_boutique.jpg&quot;)

I use this code in Selenium

background = driver.find_element_by_css_selector('body').value_of_css_property('background-image')

how can i use this in Scrapy using Css Selector or Xpath?

Upvotes: 1

Views: 400

Answers (1)

eLRuLL
eLRuLL

Reputation: 18799

In scrapy you can use CSS selectors directly:

You can get the node attribute with:

style = response.css('body::attr(style)').extract_first()

After this I am afraid scrapy doesn't offer something like value_of_css_property directly, so you'll have to parse the attribute yourself:

value = response.css("body::attr(style)").re_first('background-image: (.*)$')

Upvotes: 1

Related Questions