-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a repeat
option for extractors to WebsiteAgent
#1769
Conversation
33c914d
to
f67da0b
Compare
@@ -42,7 +44,8 @@ class WebsiteAgent < Agent | |||
"extract": { | |||
"url": { "css": "#comic img", "value": "@src" }, | |||
"title": { "css": "#comic img", "value": "@title" }, | |||
"body_text": { "css": "div.main", "value": "string(.)" } | |||
"body_text": { "css": "div.main", "value": "string(.)" }, | |||
"page_title": { "css": "title", "value": "string(.)" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this have repeat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, that's what I intended. I'll fix it.
051082e
to
d72d773
Compare
This allows user to include a value that only appears once in a content in all events created from the content.
d72d773
to
bd9455d
Compare
This allows user to include a value that only appears once in a resource in all events created from it, for all extraction types, which has been possible only in the html/xml extraction types owing to the power of XPath, but never in regexp/json. @cantino What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a really useful addition.
num_tuples = output.each_value.first.size | ||
num_tuples = output.each_value.inject(nil) { |num, value| | ||
case size = value.size | ||
when Float::INFINITY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When does this happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what Repeater#size returns, meaning it is an infinite list. num_tuples
is being set to a finite number that is the size of finite lists, so it is counted out here.
This is useful such as when you want to include the title of a page in all events created from the page. In combination with the
template
option (#1743) and the_loop_
variable (#1768), I guess you could finally achieve crawling of paginated contents properly, by adding the link to the next page to the last event created by a check, incrementing the nest level, feeding it back to the agent via a TriggerAgent with conditions on the presence of the said link and the nest level.The implementation with regard to Repeater may be too tricky, and the wording of documentation seemed far beyond me, and I'm not 100% certain as to the naming of the option, so any feedback is welcome!