【问题标题】:selecting css properties value from inline style using xpath使用 xpath 从内联样式中选择 css 属性值
【发布时间】:2017-06-10 19:06:40
【问题描述】:
<a href="http://link.com">
 <div style="background-image:url(https://imageurl.jpeg);">
  </div>
</a>

xpath 中是否有一个选择器允许获取某个 css 声明的值,记住它是一个内联样式。

在上面的代码示例中,我想检索“background-image”属性的值。

【问题讨论】:

  • 考虑使用“selenium webdriver”或Python“scrapy”模块

标签: xpath web-scraping


【解决方案1】:

你可以使用 xpath :

substring-before(substring-after(//div/@style, 'background-image:url('), ')')

【讨论】:

  • 完美答案,基本找到url周围字符的开头和结尾。谢谢!
猜你喜欢
  • 2012-01-15
  • 1970-01-01
  • 1970-01-01
  • 2012-03-05
  • 2018-08-08
  • 1970-01-01
  • 2013-09-06
  • 2013-12-06
  • 2020-03-19
相关资源
最近更新 更多