All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.codecraft.webmagic.selector.PlainText Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package us.codecraft.webmagic.selector;

import java.util.ArrayList;
import java.util.List;

/**
 * Selectable plain text.
* Can not be selected by XPath or CSS Selector. * * @author [email protected]
* @since 0.1.0 */ public class PlainText extends AbstractSelectable { protected List sourceTexts; public PlainText(List sourceTexts) { this.sourceTexts = sourceTexts; } public PlainText(String text) { this.sourceTexts = new ArrayList(); sourceTexts.add(text); } public static PlainText create(String text) { return new PlainText(text); } @Override public Selectable xpath(String xpath) { throw new UnsupportedOperationException("XPath can not apply to plain text. Please check whether you use a previous xpath with attribute select (/@href etc)."); } @Override public Selectable $(String selector) { throw new UnsupportedOperationException("$ can not apply to plain text. Please check whether you use a previous xpath with attribute select (/@href etc)."); } @Override public Selectable $(String selector, String attrName) { throw new UnsupportedOperationException("$ can not apply to plain text. Please check whether you use a previous xpath with attribute select (/@href etc)."); } @Override public Selectable smartContent() { throw new UnsupportedOperationException("Smart content can not apply to plain text. Please check whether you use a previous xpath with attribute select (/@href etc)."); } @Override public Selectable links() { throw new UnsupportedOperationException("Links can not apply to plain text. Please check whether you use a previous xpath with attribute select (/@href etc)."); } @Override public List nodes() { List nodes = new ArrayList(getSourceTexts().size()); for (String string : getSourceTexts()) { nodes.add(PlainText.create(string)); } return nodes; } @Override protected List getSourceTexts() { return sourceTexts; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy