From f0ac299bb33ab3fc82a111b97a547562ffd0e03f Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Thu, 19 Aug 2021 08:44:05 +0900 Subject: [PATCH] add page class, and Page#links --- src/mechanize/page.cr | 9 +++++++++ src/mechanize/page/link.cr | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/mechanize/page/link.cr diff --git a/src/mechanize/page.cr b/src/mechanize/page.cr index d9f0f04..4b7a474 100644 --- a/src/mechanize/page.cr +++ b/src/mechanize/page.cr @@ -1,5 +1,6 @@ require "./file" require "./utils/element_matcher" +require "./page/link" class MechanizeCr::Page < MechanizeCr::File include MechanzeCr::ElementMatcher @@ -33,6 +34,14 @@ class MechanizeCr::Page < MechanizeCr::File end.to_a end + def links + links = %w{a area}.map do |tag| + css(tag).map do |node| + PageContent::Link.new(node, @mech, self) + end + end.flatten + end + # generate form_with, forms_with methods # ex) form_with({:name => "login_form"}) # it detects form(s) which match conditions. diff --git a/src/mechanize/page/link.cr b/src/mechanize/page/link.cr new file mode 100644 index 0000000..469c7ac --- /dev/null +++ b/src/mechanize/page/link.cr @@ -0,0 +1,15 @@ +class MechanizeCr::PageContent::Link + property node : Lexbor::Node + property page : Page + property mech : Mechanize + + def initialize(node, mech, page) + @node = node + @page = page + @mech = mech + # @attributes = node + # @href = node['href'] + # @text = nil + # @uri = nil + end +end