在 Scrapy 中使用 Selector 等同于 value_of_css_property 是什么?
What is equivalent of value_of_css_property in Scrapy using Selector?
用于从此标签获取背景
<body style="background-image: url("http://www.auchandrive.fr/drive/static-media/public2/zones_edit/bannieres/_2016/S49/background_festif2016_boutique.jpg")
我在 Selenium
中使用此代码
background = driver.find_element_by_css_selector('body').value_of_css_property('background-image')
如何使用 Css 选择器或 Xpath 在 Scrapy 中使用它?
在scrapy中可以直接使用CSS selectors:
您可以通过以下方式获取节点属性:
style = response.css('body::attr(style)').extract_first()
恐怕scrapy不会直接提供类似value_of_css_property
的东西,所以你必须自己解析属性:
value = response.css("body::attr(style)").re_first('background-image: (.*)$')
用于从此标签获取背景
<body style="background-image: url("http://www.auchandrive.fr/drive/static-media/public2/zones_edit/bannieres/_2016/S49/background_festif2016_boutique.jpg")
我在 Selenium
中使用此代码background = driver.find_element_by_css_selector('body').value_of_css_property('background-image')
如何使用 Css 选择器或 Xpath 在 Scrapy 中使用它?
在scrapy中可以直接使用CSS selectors:
您可以通过以下方式获取节点属性:
style = response.css('body::attr(style)').extract_first()
恐怕scrapy不会直接提供类似value_of_css_property
的东西,所以你必须自己解析属性:
value = response.css("body::attr(style)").re_first('background-image: (.*)$')