设为首页 加入收藏

TOP

GraphQuery - Powerful html/xml query language(三)
2019-09-17 17:35:56 】 浏览:44
Tags:GraphQuery Powerful html/xml query language
;)
Use CSS selector to select elements
json json(JSONSelector) json("title") Use json path to select elements
xpath xpath(XpathSelector) xpath("//title") Use Xpath selector to select elements
regex regex(RegexSelector) regex("(.*?)") Use Regex selector to select elements
trim trim() trim() Clear spaces and line breaks before and after the string
template template(TemplateStr) template("[{$}]") Add characters before and after variables
attr attr(AttributeName) attr("lang") Extract the property of the current node
eq eq(Index) eq("0") Take the nth element in the current node collection
string string() string() Extract the current node native string
text text() text() Extract the text of the current node
link link(KeyName) link("title") Returns the current text of the specified key
replace replace(A, B) replace("a", "b") Replace all A in the current node to B

More detailed introduction to pipeline and function, please go to docs.

Install

GraphQuery is currently only native to Golang, but for other languages, it can be invoked as a service.

1. Golang:

go get github.com/storyicon/graphquery

Create a new go file :

package main

import (
    "encoding/json"
    "log"

    "github.com/storyicon/graphquery"
)

func main() {
    document := `
        <html>
            <body>
                <a href="01.html">Page 1</a>
                <a href="02.html">Page 2</a>
                <a href="03.html">Page 3</a>
            </body>
        </html>
    `
    expr := "{ anchor `css(\"a\")` [ content `text()` ] }"
    response := graphquery.ParseFromString(document, expr)
    bytes, _ := json.Marshal(response.Data)
    log.Println(string(bytes))
}

Run the go file, the output is as follows :

{"anchor":["Page 1","Page 2","Page 3"]}

2. Other language

We use the HTTP protocol to provide a cross-language solution for developers to query GraphQuery using any back-end language you want to use to access the specified port after starting the service.

GraphQuery-http : Cross language solution for GraphQuery

You can also use RPC for communication, but currently you may need to do this yourself, because the RPC project on GraphQuery is still under development.
At the same time, We welcome the contributors to write native support code for other languages ??in GraphQuery.

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇[原创]分布式系统之缓存的微观应.. 下一篇java 进销存 crm 客户管理 库存管..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目