gdom - DOM Traversing and Scraping using GraphQL
GDOM
GDOM is the next generation of web-parsing, powered by GraphQL syntax and the Graphene framework.
Install it typing in your console:
pip install gdomDEMO: Try GDOM online
Usage
You can either do gdom --test to start a test server for testing queries or
gdom QUERY_FILEThis command will write in the standard output (or other output if specified via --output) the resulting JSON.
Your QUERY_FILE could look similar to this:
{
page(url:"http://news.ycombinator.com") {
items: query(selector:"tr.athing") {
rank: text(selector:"td span.rank")
title: text(selector:"td.title a")
sitebit: text(selector:"span.comhead a")
url: attr(selector:"td.title a", name:"href")
attrs: next {
score: text(selector:"span.score")
user: text(selector:"a:eq(0)")
comments: text(selector:"a:eq(2)")
}
}
}
} Advanced usage
If you want to generalize your gdom query to any page, just rewrite your query file adding the $page var. So should look to something like this:
query ($page: String) {
page(url:$page) {
# ...
}
} And then, query it like:
gdom QUERY_FILE http://news.ycombinator.com 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!