antchfx / Jsonquery
Licence: mit
jsonq package for Go. Golang XPath query for JSON query.
Stars: ✭ 134
Labels
Projects that are alternatives of or similar to Jsonquery
Python Spider
豆瓣电影top250、斗鱼爬取json数据以及爬取美女图片、淘宝、有缘、CrawlSpider爬取红娘网相亲人的部分基本信息以及红娘网分布式爬取和存储redis、爬虫小demo、Selenium、爬取多点、django开发接口、爬取有缘网信息、模拟知乎登录、模拟github登录、模拟图虫网登录、爬取多点商城整站数据、爬取微信公众号历史文章、爬取微信群或者微信好友分享的文章、itchat监听指定微信公众号分享的文章
Stars: ✭ 615 (+358.96%)
Mutual labels: xpath
Domquery
PHP library for easy 'jQuery like' DOM traversing and manipulation.
Stars: ✭ 84 (-37.31%)
Mutual labels: xpath
Sirix
SirixDB is a temporal, evolutionary database system, which uses an accumulate only approach. It keeps the full history of each resource. Every commit stores a space-efficient snapshot through structural sharing. It is log-structured and never overwrites data. SirixDB uses a novel page-level versioning approach called sliding snapshot.
Stars: ✭ 638 (+376.12%)
Mutual labels: xpath
Xom
XOM™ is a new XML object model. It is an open source (LGPL), tree-based API for processing XML with Java that strives for correctness, simplicity, and performance, in that order.
Stars: ✭ 38 (-71.64%)
Mutual labels: xpath
Graphquery
GraphQuery is a query language and execution engine tied to any backend service.
Stars: ✭ 112 (-16.42%)
Mutual labels: xpath
Internettools
XPath/XQuery 3.1 interpreter for Pascal with compatibility modes for XPath 2.0/XQuery 1.0/3.0, custom and JSONiq extensions, XML/HTML parsers and classes for HTTP/S requests
Stars: ✭ 82 (-38.81%)
Mutual labels: xpath
Amazon Mobile Sentiment Analysis
Opinion mining of Mobile reviews on Amazon platform
Stars: ✭ 19 (-85.82%)
Mutual labels: xpath
Parsel
Parsel lets you extract data from XML/HTML documents using XPath or CSS selectors
Stars: ✭ 628 (+368.66%)
Mutual labels: xpath
Markup
A Swift package for working with HTML, XML, and other markup languages, based on libxml2.
Stars: ✭ 93 (-30.6%)
Mutual labels: xpath
Docs
《数据采集从入门到放弃》源码。内容简介:爬虫介绍、就业情况、爬虫工程师面试题 ;HTTP协议介绍; Requests使用 ;解析器Xpath介绍; MongoDB与MySQL; 多线程爬虫; Scrapy介绍 ;Scrapy-redis介绍; 使用docker部署; 使用nomad管理docker集群; 使用EFK查询docker日志
Stars: ✭ 118 (-11.94%)
Mutual labels: xpath
Pythonstudy
Python related technologies used in work: crawler, data analysis, timing tasks, RPC, page parsing, decorator, built-in functions, Python objects, multi-threading, multi-process, asynchronous, redis, mongodb, mysql, openstack, etc.
Stars: ✭ 103 (-23.13%)
Mutual labels: xpath
Jsoup
jsoup: the Java HTML parser, built for HTML editing, cleaning, scraping, and XSS safety.
Stars: ✭ 9,184 (+6753.73%)
Mutual labels: xpath
jsonquery
Overview
jsonquery is an XPath query package for JSON document, lets you extract data from JSON documents through an XPath expression. Built-in XPath expression cache avoid re-compile XPath expression each query.
Getting Started
Install Package
go get github.com/antchfx/jsonquery
Load JSON document from URL.
doc, err := jsonquery.LoadURL("http://www.example.com/feed?json")
Load JSON document from string.
s :=`{
"name":"John",
"age":31,
"city":"New York"
}`
doc, err := jsonquery.Parse(strings.NewReader(s))
Load JSON document from io.Reader.
f, err := os.Open("./books.json")
doc, err := jsonquery.Parse(f)
Find authors of all books in the store.
list := jsonquery.Find(doc, "store/book/*/author")
// or equal to
list := jsonquery.Find(doc, "//author")
// or by QueryAll()
nodes, err := jsonquery.QueryAll(doc, "//a")
Find the third book.
book := jsonquery.Find(doc, "//book/*[3]")
Find the last book.
book := jsonquery.Find(doc, "//book/*[last()]")
Find all books that have an isbn number.
list := jsonquery.Find(doc, "//book/*[isbn]")
Find all books priced less than 10.
list := jsonquery.Find(doc, "//book/*[price<10]")
Examples
func main() {
s := `{
"name": "John",
"age" : 26,
"address" : {
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers": [
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}`
doc, err := jsonquery.Parse(strings.NewReader(s))
if err != nil {
panic(err)
}
name := jsonquery.FindOne(doc, "name")
fmt.Printf("name: %s\n", name.InnerText())
var a []string
for _, n := range jsonquery.Find(doc, "phoneNumbers/*/number") {
a = append(a, n.InnerText())
}
fmt.Printf("phone number: %s\n", strings.Join(a, ","))
if n := jsonquery.FindOne(doc, "address/streetAddress"); n != nil {
fmt.Printf("address: %s\n", n.InnerText())
}
}
Implement Principle
If you are familiar with XPath and XML, you can easily figure out how to write your XPath expression.
{
"name":"John",
"age":30,
"cars": [
{ "name":"Ford", "models":[ "Fiesta", "Focus", "Mustang" ] },
{ "name":"BMW", "models":[ "320", "X3", "X5" ] },
{ "name":"Fiat", "models":[ "500", "Panda" ] }
]
}
The above JSON document will be convert to similar to XML document by the JSONQuery, like below:
<name>John</name>
<age>30</age>
<cars>
<element>
<name>Ford</name>
<models>
<element>Fiesta</element>
<element>Focus</element>
<element>Mustang</element>
</models>
</element>
<element>
<name>BMW</name>
<models>
<element>320</element>
<element>X3</element>
<element>X5</element>
</models>
</element>
<element>
<name>Fiat</name>
<models>
<element>500</element>
<element>Panda</element>
</models>
</element>
</cars>
Notes: element
is empty element that have no any name.
List of XPath query packages
Name | Description |
---|---|
htmlquery | XPath query package for the HTML document |
xmlquery | XPath query package for the XML document |
jsonquery | XPath query package for the JSON document |
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].