[Gambas-user] XmlElement.GetChildrenByFilter misbehaving ?
T Lee Davidson
t.lee.davidson at gmail.com
Sat Feb 23 21:41:32 CET 2019
XmlElement.GetChildrenByFilter() does not seem to correctly match CSS selectors and sometimes allows partial matches on an
attribute value.
Given the following HTML ("test.html"):
<html>
<body>
<div class="userrow"> <!-- If this div is removed; or if "user" is not in the class name, the code works as expected. -->
<div class="user">
<a href="https://homedomain.dom/hottlipps"></a>
</div>
<div class="userspacer"></div>
<div class="user">
<a href="https://homedomain.dom/jimjohnson"></a>
</div>
<div class="userspacer"></div>
<div class="user">
<a href="https://homedomain.dom/jackstone"></a>
</div>
</div>
</body>
</html>
And the following code:
' Gambas module file
Public Sub Main()
Dim HtmlContent As New HtmlDocument
Dim Users As XmlElement[]
HtmlContent.HtmlFromString(File.Load(Application.Path &/ "test.html"))
Users = HtmlContent.Body.GetChildrenByFilter(".user > a") ' Gets div tags also; instead of just anchor tags.
For Each MyElement As XmlElement In Users
Print MyElement.tagname, MyElement.classname
Next
End
I get:
div user
a
div userspacer
div user
a
div userspacer
div user
a
Is this one or more bugs, a misunderstanding on my part, or a combination of both?
Project attached.
___
Lee
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestCommandical-0.0.4.tar.gz
Type: application/gzip
Size: 12279 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190223/fbd06dc1/attachment.gz>
More information about the User
mailing list