add xsearch command
parent
28598eb3ab
commit
48667f7af8
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func cmdXSearch(c *cli.Context) error {
|
||||
u, err := url.Parse("http://mastodonsearch.jp/cross/")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params := url.Values{}
|
||||
params.Set("q", c.Args().First())
|
||||
u.RawQuery = params.Encode()
|
||||
doc, err := goquery.NewDocument(u.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
doc.Find(".post").Each(func(n int, elem *goquery.Selection) {
|
||||
href, ok := elem.Find(".mst_content a").Attr("href")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
text := elem.Find(".mst_content p").Text()
|
||||
fmt.Println(href)
|
||||
fmt.Println(text)
|
||||
fmt.Println()
|
||||
})
|
||||
return nil
|
||||
}
|
|
@ -285,6 +285,11 @@ func makeApp() *cli.App {
|
|||
Usage: "search mikami",
|
||||
Action: cmdMikami,
|
||||
},
|
||||
{
|
||||
Name: "xsearch",
|
||||
Usage: "cross search",
|
||||
Action: cmdXSearch,
|
||||
},
|
||||
}
|
||||
app.Setup()
|
||||
return app
|
||||
|
|
Loading…
Reference in New Issue