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

us.codecraft.webmagic.utils.ExtractorUtils Maven / Gradle / Ivy

The newest version!
package us.codecraft.webmagic.utils;

import us.codecraft.webmagic.model.annotation.ExtractBy;
import us.codecraft.webmagic.selector.*;

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

/**
 * Tools for annotation converting. 
* * @author [email protected]
* @since 0.2.1 */ public class ExtractorUtils { public static Selector getSelector(ExtractBy extractBy) { String value = extractBy.value(); Selector selector; switch (extractBy.type()) { case Css: selector = new CssSelector(value); break; case Regex: selector = new RegexSelector(value); break; case XPath: selector = new XpathSelector(value); break; case JsonPath: selector = new JsonPathSelector(value); break; default: selector = new XpathSelector(value); } return selector; } public static List getSelectors(ExtractBy[] extractBies) { List selectors = new ArrayList(); if (extractBies == null) { return selectors; } for (ExtractBy extractBy : extractBies) { selectors.add(getSelector(extractBy)); } return selectors; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy