package us.codecraft.webmagic.selector;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;

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

/**
 * @author code4crafter@gmail.com
 * @since 0.3.0
 */
public abstract class BaseElementSelector implements Selector, ElementSelector {

    @Override
    public String select(String text) {
        if (text != null) {
            return select(Jsoup.parse(text));
        }
        return null;
    }

    @Override
    public List<String> selectList(String text) {
        if (text != null) {
            return selectList(Jsoup.parse(text));
        } else {
            return new ArrayList<String>();
        }
    }

    public Element selectElement(String text) {
        if (text != null) {
            return selectElement(Jsoup.parse(text));
        }
        return null;
    }

    public List<Element> selectElements(String text) {
        if (text != null) {
            return selectElements(Jsoup.parse(text));
        } else {
            return new ArrayList<Element>();
        }
    }

    public abstract Element selectElement(Element element);

    public abstract List<Element> selectElements(Element element);

    public abstract boolean hasAttribute();

}

@@ -58,16 +58,49 @@
 .Jsoup;%0A
+import org.jsoup.nodes.Document;%0A
 import o
@@ -123,16 +123,16 @@
 lement;%0A
-
 %0Aimport 
@@ -314,16 +314,512 @@
 lector %7B
+%0A    private Document parse(String text) %7B%0A        if (text == null) %7B%0A            return null;%0A        %7D%0A%0A        // Jsoup could not parse %3Ctr%3E%3C/tr%3E or %3Ctd%3E%3C/td%3E tag directly%0A        // https://stackoverflow.com/questions/63607740/jsoup-couldnt-parse-tr-tag%0A        if ((text.startsWith(%22%3Ctr%3E%22) && text.endsWith(%22%3C/tr%3E%22))%0A                %7C%7C (text.startsWith(%22%3Ctd%3E%22) && text.endsWith(%22%3C/td%3E%22))) %7B%0A            text = %22%3Ctable%3E%22 + text + %22%3C/table%3E%22;%0A        %7D%0A        return Jsoup.parse(text);%0A    %7D
 %0A%0A    @O
@@ -920,22 +920,16 @@
  select(
-Jsoup.
 parse(te
@@ -1094,22 +1094,16 @@
 ectList(
-Jsoup.
 parse(te
@@ -1295,22 +1295,16 @@
 Element(
-Jsoup.
 parse(te
@@ -1422,32 +1422,32 @@
 text != null) %7B%0A
+
             retu
@@ -1464,22 +1464,16 @@
 lements(
-Jsoup.
 parse(te

Enhance Jsoup could parse tr td tag directly