From 8b54094514919d54c6dceff380aa676d90ce70f1 Mon Sep 17 00:00:00 2001 From: suym845 Date: Sat, 25 Aug 2018 15:35:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=9B=B4=E6=8E=A5=E7=94=A8?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=90=8E=E7=9A=84RegexSelector=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 不需要每次都重复编译同一条正则表达式 --- .../us/codecraft/webmagic/selector/AbstractSelectable.java | 5 +++++ .../java/us/codecraft/webmagic/selector/Selectable.java | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/webmagic-core/src/main/java/us/codecraft/webmagic/selector/AbstractSelectable.java b/webmagic-core/src/main/java/us/codecraft/webmagic/selector/AbstractSelectable.java index e2bb55215..00c9bba4b 100644 --- a/webmagic-core/src/main/java/us/codecraft/webmagic/selector/AbstractSelectable.java +++ b/webmagic-core/src/main/java/us/codecraft/webmagic/selector/AbstractSelectable.java @@ -83,6 +83,11 @@ public Selectable regex(String regex, int group) { RegexSelector regexSelector = Selectors.regex(regex, group); return selectList(regexSelector, getSourceTexts()); } + + @Override + public Selectable regex(RegexSelector selector) { + return selectList(selector, getSourceTexts()); + } @Override public Selectable replace(String regex, String replacement) { diff --git a/webmagic-core/src/main/java/us/codecraft/webmagic/selector/Selectable.java b/webmagic-core/src/main/java/us/codecraft/webmagic/selector/Selectable.java index 9412cfce4..5504e6b95 100644 --- a/webmagic-core/src/main/java/us/codecraft/webmagic/selector/Selectable.java +++ b/webmagic-core/src/main/java/us/codecraft/webmagic/selector/Selectable.java @@ -82,6 +82,13 @@ public interface Selectable { * @return new Selectable after extract */ public Selectable regex(String regex, int group); + + /** + * select list with RegexSelector + * @param selector selector + * @return Selectable after extract + */ + public Selectable regex(RegexSelector selector); /** * replace with regex