Fix sample.lua iteration

sample.lua did not iterate over the output of :select() correctly. It had been written assuming the keys were attributes, when in fact the keys are numbers, and the values are attributes. This caused an error when running the sample script.
This commit is contained in:
yaw-man 2021-08-18 01:12:29 -03:00 committed by Vadim A. Misbakh-Soloviov
parent b66ae0c21e
commit baa3655ca3

View File

@ -25,7 +25,7 @@ p(root)
print("\nchapters")
local sel, chapters = root("ol.chapters > li"), {}
for e in pairs(sel) do
for _, e in ipairs(sel) do
table.insert(chapters, e:getcontent())
end
-- print
@ -35,7 +35,7 @@ end
print("\ncontacts")
local sel, contacts = root("ul.contacts span[class]"), {}
for e in pairs(sel) do
for _, e in ipairs(sel) do
local id = e.parent.parent.id -- li > a > span
contacts[id] = contacts[id] or {}
contacts[id][e.classes[1]] = e:getcontent()
@ -50,7 +50,7 @@ end
print("\nmicrodata")
local sel, scopes = root("[itemprop]"), {}
for prop in pairs(sel) do
for _, prop in ipairs(sel) do
if prop.attributes["itemscope"] then goto nextprop end
local descendantscopes, scope = {}, prop
while true do