extract common element to a local variable

pull/13962/head
Delyan Angelov 2022-04-07 18:16:13 +03:00
parent 2720e657c2
commit 2a7c182f98
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 3 additions and 6 deletions

View File

@ -15,12 +15,9 @@ fn main() {
// html.DocumentObjectModel.get_tag_by_attribute_value() retrieves all the tags in the document that has the given attribute name and value.
tags := doc.get_tag_by_attribute_value('class', 'list_article_item')
for tag in tags {
href := tag.children[1].children[0].children[0].children[0].attributes['href'] or {
panic('key not found')
}
title := tag.children[1].children[0].children[0].children[0].attributes['title'] or {
panic('key not found')
}
el := tag.children[1].children[0].children[0].children[0]
href := el.attributes['href'] or { panic('key not found') }
title := el.attributes['title'] or { panic('key not found') }
println('href: $href')
println('title: $title')
println('')