mirror of
https://github.com/msva/lua-htmlparser.git
synced 2024-11-04 23:34:20 +00:00
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:
parent
b66ae0c21e
commit
baa3655ca3
@ -25,7 +25,7 @@ p(root)
|
|||||||
|
|
||||||
print("\nchapters")
|
print("\nchapters")
|
||||||
local sel, chapters = root("ol.chapters > li"), {}
|
local sel, chapters = root("ol.chapters > li"), {}
|
||||||
for e in pairs(sel) do
|
for _, e in ipairs(sel) do
|
||||||
table.insert(chapters, e:getcontent())
|
table.insert(chapters, e:getcontent())
|
||||||
end
|
end
|
||||||
-- print
|
-- print
|
||||||
@ -35,7 +35,7 @@ end
|
|||||||
|
|
||||||
print("\ncontacts")
|
print("\ncontacts")
|
||||||
local sel, contacts = root("ul.contacts span[class]"), {}
|
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
|
local id = e.parent.parent.id -- li > a > span
|
||||||
contacts[id] = contacts[id] or {}
|
contacts[id] = contacts[id] or {}
|
||||||
contacts[id][e.classes[1]] = e:getcontent()
|
contacts[id][e.classes[1]] = e:getcontent()
|
||||||
@ -50,7 +50,7 @@ end
|
|||||||
|
|
||||||
print("\nmicrodata")
|
print("\nmicrodata")
|
||||||
local sel, scopes = root("[itemprop]"), {}
|
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
|
if prop.attributes["itemscope"] then goto nextprop end
|
||||||
local descendantscopes, scope = {}, prop
|
local descendantscopes, scope = {}, prop
|
||||||
while true do
|
while true do
|
||||||
|
Loading…
Reference in New Issue
Block a user