OpenSystemsLab / q.nim

Query HTML/XML elements using a CSS3 or jQuery-like selector syntax
http://huy.im
MIT License
57 stars 2 forks source link

Selecting nodes by attribute values #1

Open GarryGaller opened 8 years ago

GarryGaller commented 8 years ago
let htmldoc ="""
<html>
<body>
<a href="12345.txt">12345.txt</a>
<a href="12346.txt">12346.txt</a>
<a href="12347">12347</a>
</body>
</html>
"""

echo q(htmldoc).select("a[href=12345.txt]")
#output: @[<a href="12345.txt">12345.txt</a>, <a href="12346.txt">12346.txt</a>, <a href="12347">12347</a>]

let htmldoc2 ="""
<html>
<body>
<a href="12345">12345</a>
<a href="12346">12346</a>
<a href="12347">12347</a>
</body>
</html>
"""

echo q(htmldoc2).select("a[href=12347]") 
#output:  @[<a href="12345">12345</a>, <a href="12346">12346</a>, <a href="12347">12347</a>]

let htmldoc3 ="""
<html>
<body>
<a href="a12345">a12345</a>
<a href="a12346">a12346</a>
<a href="a12347">a12347</a>
</body>
</html>
"""
# Correctly working soon:
echo q(htmldoc3).select("a[href=a12347]")
#output: @[<a href="a12347">a12347</a>]
ba0f3 commented 8 years ago

I will check this soon, just back home from a long vacation

ghost commented 7 years ago

To anyone, who found this library and wonders if it works: it works