1 Star 0 Fork 3

bizbook / xsoup

forked from bluesky8318 / xsoup 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Xsoup

Build Status

XPath selector based on Jsoup.

Get started:

    @Test
    public void testSelect() {

        String html = "<html><div><a href='https://github.com'>github.com</a></div>" +
                "<table><tr><td>a</td><td>b</td></tr></table></html>";

        Document document = Jsoup.parse(html);

        String result = Xsoup.compile("//a/@href").evaluate(document).get();
        Assert.assertEquals("https://github.com", result);

        List<String> list = Xsoup.compile("//tr/td/text()").evaluate(document).list();
        Assert.assertEquals("a", list.get(0));
        Assert.assertEquals("b", list.get(1));
    }

Performance:

Xsoup use Jsoup as HTML parser.

Compare with another most used XPath selector for HTML - HtmlCleaner, Xsoup is much faster:

Normal HTML, size 44KB
XPath: "//a"	
Run for 2000 times

Environment:Mac Air MD231CH/A 
CPU: 1.8Ghz Intel Core i5
Operation Xsoup HtmlCleaner
parse 3,207(ms) 7,999(ms)
select 95(ms) 380(ms)

Syntax supported:

XPath1.0:

Name Expression Support
nodename nodename yes
immediate parent / yes
parent // yes
attribute [@key=value] yes
nth child tag[n] yes
attribute /@key yes
wildcard in tagname /* yes
wildcard in attribute /[@*] yes
function function() part
or a | b yes since 0.2.0
parent in path . or .. no
predicates price>35 no
predicates logic @class=a or @class=b yes since 0.2.0

Function supported:

In Xsoup, we use some function (maybe not in Standard XPath 1.0):

Expression Description Standard XPath
text(n) nth text content of element(0 for all) text() only
allText() text including children not support
tidyText() text including children, well formatted not support
html() innerhtml of element not support
outerHtml() outerHtml of element not support
regex(@attr,expr,group) use regex to extract content not support

Extended syntax supported:

These XPath syntax are extended only in Xsoup (for convenience in extracting HTML, refer to Jsoup CSS Selector):

Name Expression Support
attribute value not equals [@key!=value] yes
attribute value start with [@key~=value] yes
attribute value end with [@key$=value] yes
attribute value contains [@key*=value] yes
attribute value match regex [@key~=value] yes

License

MIT License, see file LICENSE

Bitdeli Badge

The MIT License Copyright (c) 2009, 2010, 2011, 2012, 2013 Jonathan Hedley <jonathan@hedley.net> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

When jsoup meets XPath. 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/bizbook/xsoup.git
git@gitee.com:bizbook/xsoup.git
bizbook
xsoup
xsoup
master

搜索帮助