Lxml css选择通配符
如何使用 cssselect 获取所有通配符元素?
例如:
content = """
<table>
<tr id='Awesome1234'><a href="link1"></a></tr>
<tr id='Awesome5678'><a href="link2"></a></tr>
</table>
"""
doc = lxml.html.fromstring(html)
links = lxml.cssselection('tr.Awesome* a')
for link in links:
print link.get('href')
我希望它输出:
link1
link2
Is this possible with cssselect?如果没有,我怎样才能得到这个? (x路径?)
How do I get all the wildcard elements using cssselect?
For example:
content = """
<table>
<tr id='Awesome1234'><a href="link1"></a></tr>
<tr id='Awesome5678'><a href="link2"></a></tr>
</table>
"""
doc = lxml.html.fromstring(html)
links = lxml.cssselection('tr.Awesome* a')
for link in links:
print link.get('href')
I want it to output:
link1
link2
Is this possible with cssselect? If not, how can I get this? (xpath?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
^=
比较运算符似乎适合您:^=
comparison operator seems for you:使用以下 XPath 表达式(不需要 css):
此 XPath 表达式选择上下文节点的所有具有
id
属性的tr
子节点,其字符串值以字符串“Awsome”开头。Use the following XPath expression (no css is required):
This XPath expression selects all
tr
children of the context node that have anid
attribute, whose string value starts with the string 'Awsome'.