scrape Web 爬虫

程序名称:scrape

授权协议: BSD

操作系统: 跨平台

开发语言: Google Go

scrape 介绍

scrape 是一个简单高级的 Web 爬虫库,使用 Go 语言开发。

示例代码

package main

import (
    "fmt"
    "net/http"

    "github.com/yhat/scrape"
    "golang.org/x/net/html"
    "golang.org/x/net/html/atom"
)

func main() {
    // request and parse the front page
    resp, err := http.Get("https://news.ycombinator.com/")
    if err != nil {
        panic(err)
    }
    root, err := html.Parse(resp.Body)
    if err != nil {
        panic(err)
    }

    // define a matcher
    matcher := func(n *html.Node) bool {
        // must check for nil values
        if n.DataAtom == atom.A && n.Parent != nil && n.Parent.Parent != nil {
            return scrape.Attr(n.Parent.Parent, "class") == "athing"
        }
        return false
    }
    // grab all articles and print them
    articles := scrape.FindAll(root, matcher)
    for i, article := range articles {
        fmt.Printf("%2d %s (%s)\n", i, scrape.Text(article), scrape.Attr(article, "href"))
    }
}

scrape 官网

https://github.com/yhat/scrape

相关编程语言

Pacman 是一个软件包管理器, 作为 ArchLinux 发行版...
Smb4K 是KDE下的网络共享浏览器 更多屏幕截图请看:...
Wine (“Wine Is Not an Emulator” 的首字母缩写)...
虚拟桌面软件,可管理最多9个虚拟桌面,你可以用热键...
UNetbootin (Universal Netboot Installer)为一种跨...
Cobbler 可以用来快速建立 Linux 网络安装环境,它已...