This commit is contained in:
Alex Yatskov 2016-01-08 22:19:36 +09:00
parent 51d16713f3
commit 25965e83d8

View File

@ -32,6 +32,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
@ -49,6 +50,8 @@ func scrape(url, css, attr string) (string, error) {
return "", fmt.Errorf("no selection for '%s'", css) return "", fmt.Errorf("no selection for '%s'", css)
} }
sel = sel.First()
var res string var res string
if len(attr) == 0 { if len(attr) == 0 {
res = sel.Text() res = sel.Text()
@ -89,12 +92,20 @@ func export(path string, r io.Reader) error {
return nil return nil
} }
func usage() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] conf src\n", path.Base(os.Args[0]))
fmt.Fprintf(os.Stderr, "http://foosoft.net/projects/scrawl/\n\n")
fmt.Fprintf(os.Stderr, "Parameters:\n")
flag.PrintDefaults()
}
func main() { func main() {
var ( var (
attr = flag.String("attr", "", "attribute to query") attr = flag.String("attr", "", "attribute to query")
verbose = flag.Bool("verbose", false, "verbose output") verbose = flag.Bool("verbose", false, "verbose output")
) )
flag.Usage = usage
flag.Parse() flag.Parse()
if flag.NArg() < 2 { if flag.NArg() < 2 {