mirror of
https://github.com/msva/lua-htmlparser.git
synced 2024-11-27 12:44:22 +00:00
:not() seems to be functioning now
needs some tidying up and some more test runs
This commit is contained in:
parent
d932191a52
commit
48183bbf04
@ -103,12 +103,22 @@ local function select(self, s)
|
|||||||
resultset = resultset + init
|
resultset = resultset + init
|
||||||
end
|
end
|
||||||
if part == "*" then goto nextpart end
|
if part == "*" then goto nextpart end
|
||||||
for t, w in string.gmatch(part, "([%[#%.]?)([^%[%]#%.]+)") do
|
local match, filter
|
||||||
if t == "" then resultset = resultset * self.deeperelements[w]
|
for t, w in string.gmatch(part, "([:%[#.]?)([^:%(%[#.%]%)]+)%]?%)?") do
|
||||||
elseif t == "[" then resultset = resultset * self.deeperattributes[w]
|
-- TODO tidy up
|
||||||
elseif t == "#" then resultset = resultset * self.deeperids[w]
|
if t == ":" then filter = w goto nextw end
|
||||||
elseif t == "." then resultset = resultset * self.deeperclasses[w]
|
if t == "" then match = self.deeperelements[w]
|
||||||
|
elseif t == "[" then match = self.deeperattributes[w]
|
||||||
|
elseif t == "#" then match = self.deeperids[w]
|
||||||
|
elseif t == "." then match = self.deeperclasses[w]
|
||||||
end
|
end
|
||||||
|
if filter == "not" then
|
||||||
|
resultset = resultset - match
|
||||||
|
else
|
||||||
|
resultset = resultset * match
|
||||||
|
end
|
||||||
|
filter = nil
|
||||||
|
::nextw::
|
||||||
end
|
end
|
||||||
subjects = Set:new(resultset)
|
subjects = Set:new(resultset)
|
||||||
::nextpart::
|
::nextpart::
|
||||||
|
10
test.lua
10
test.lua
@ -114,3 +114,13 @@ end
|
|||||||
for node,table in pairs(scopes) do
|
for node,table in pairs(scopes) do
|
||||||
printscope(node, table)
|
printscope(node, table)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local sel = root("[itemscope]:not([itemprop])")
|
||||||
|
for i,v in ipairs(sel.nodes) do
|
||||||
|
print(v.name)
|
||||||
|
end
|
||||||
|
|
||||||
|
local sel = root("[href]:not(a)")
|
||||||
|
for i,v in ipairs(sel.nodes) do
|
||||||
|
print(v.name)
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user