Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何找到所有具有背景图像的标签?没有使用样式表。所有样式都内联在标签中。
我目前正在使用lxml和 xpath。这是我能走多远:
from lxml import html html_text = """somehtml""" doc = html.fromstring(html_text) tagWithBackgrounds = doc.xpath("//*[contains(@style,'background')]")
接下来是什么 ?
doc.xpath('//*[contains(@style,"background") and contains(@style,"url(")]')
不完美,但有效。
根据xmlme.com 的 XpathTool,这个 xPath 应该可以工作:
//*[contains(@style,'background-image')]
这是我的测试结果: