Skip to content
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

Merged
merged 2 commits into from
Nov 20, 2016

Conversation

knu
Copy link
Member

@knu knu commented Nov 1, 2016

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!

@knu knu force-pushed the website_agent_repeat_option branch 2 times, most recently from 33c914d to f67da0b Compare November 2, 2016 02:08
@@ -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(.)" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have repeat?

Copy link
Member Author

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.

@knu knu force-pushed the website_agent_repeat_option branch from 051082e to d72d773 Compare November 18, 2016 07:36
This allows user to include a value that only appears once in a content
in all events created from the content.
@knu knu force-pushed the website_agent_repeat_option branch from d72d773 to bd9455d Compare November 18, 2016 09:47
@knu
Copy link
Member Author

knu commented Nov 18, 2016

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?

Copy link
Member

@cantino cantino left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does this happen?

Copy link
Member Author

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.

@knu knu merged commit c575af9 into master Nov 20, 2016
@knu knu deleted the website_agent_repeat_option branch November 20, 2016 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants