{"record":{"id":"eabd3b8e3eec27bf","repo":"code4craft/webmagic","slug":"can-not-apply-to-plain-text-please-check-whethe","errorCode":null,"errorMessage":"$ can not apply to plain text. Please check whether you use a previous xpath with attribute select (/@href etc).","messagePattern":"\\$ can not apply to plain text\\. Please check whether you use a previous xpath with attribute select \\(/@href etc\\)\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"webmagic-core/src/main/java/us/codecraft/webmagic/selector/PlainText.java","lineNumber":37,"sourceCode":"    }\n\n    public PlainText(String text) {\n        this.sourceTexts = new ArrayList<String>();\n        sourceTexts.add(text);\n    }\n\n    public static PlainText create(String text) {\n        return new PlainText(text);\n    }\n\n    @Override\n    public Selectable xpath(String xpath) {\n        throw new UnsupportedOperationException(\"XPath can not apply to plain text. Please check whether you use a previous xpath with attribute select (/@href etc).\");\n    }\n\n    @Override\n    public Selectable $(String selector) {\n\t\tthrow new UnsupportedOperationException(\"$ can not apply to plain text. Please check whether you use a previous xpath with attribute select (/@href etc).\");\n    }\n\n    @Override\n    public Selectable $(String selector, String attrName) {\n\t\tthrow new UnsupportedOperationException(\"$ can not apply to plain text. Please check whether you use a previous xpath with attribute select (/@href etc).\");\n    }\n\n    @Override\n    public Selectable links() {\n\t\tthrow new UnsupportedOperationException(\"Links can not apply to plain text. Please check whether you use a previous xpath with attribute select (/@href etc).\");\n    }\n\n    @Override\n    public List<Selectable> nodes() {\n        List<Selectable> nodes = new ArrayList<Selectable>(getSourceTexts().size());\n        for (String string : getSourceTexts()) {\n            nodes.add(PlainText.create(string));\n        }","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/code4craft/webmagic/blob/67816a19d68a4fec4657bf1336227e046e251df2/webmagic-core/src/main/java/us/codecraft/webmagic/selector/PlainText.java#L19-L55","documentation":"PlainText's $(selector) method (CSS-style selector) always throws UnsupportedOperationException because CSS selectors need a parsed DOM, and PlainText holds only text. The hint about a previous /@href attribute select indicates the chain already reduced the content to plain text.","triggerScenarios":"Calling .$(\"...\") on a PlainText Selectable, e.g. chaining $ after links(), regex(), or an attribute xpath that returned PlainText.","commonSituations":"WebMagic users chaining CSS selectors after .links() or .regex(); result of a previous extraction was plain strings, so subsequent $() has nothing to query.","solutions":["Reorder so $() is applied to page.getHtml() before any text/attribute extraction","Replace $() with regex() when operating on plain text","Check the previous selector is not accidentally producing PlainText (e.g. /@href)"],"exampleFix":"// before\npage.getHtml().links().$(\"a.title\").all();\n// after\npage.getHtml().$(\"a.title\").all();","handlingStrategy":"validation","validationCode":"if (selectable instanceof PlainText) { throw new IllegalStateException(\"cannot call $ on plain text\"); }","typeGuard":"boolean supportsCss(Selectable s) { return !(s instanceof PlainText); }","tryCatchPattern":"try { out = selectable.$(\"a.title\"); } catch (UnsupportedOperationException e) { out = fallbackRegex(selectable); }","preventionTips":["Keep CSS $() selections at the start of chains on Html objects","Do not call $() after links() or regex()","Refactor chains so structural selectors precede text extraction"],"tags":["webmagic","css-selector","unsupported-operation","selector-chain"],"backgroundTag":"unsupported-operation","analyzedSha":"67816a19d68a4fec4657bf1336227e046e251df2","analyzedAt":"2026-09-08T11:15:28.425Z","contentChangedAt":"2026-09-08T11:15:28.425Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}