本文整理汇总了Golang中github.com/yhat/scrape.Text函数的典型用法代码示例。如果您正苦于以下问题:Golang Text函数的具体用法?Golang Text怎么用?Golang Text使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Text函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
// request and parse the front page
resp, err := http.Get("https://torguard.net/downloads.php")
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 {
if n.DataAtom == atom.Tr {
return true
}
return false
}
// grab all articles and print them
articles := scrape.FindAll(root, matcher)
for _, article := range articles {
if strings.Contains(scrape.Text(article), "DEBIAN x64Bit") {
fmt.Printf("%s\n", scrape.Text(article))
}
//fmt.Printf("%2d %s (%s)\n", i, scrape.Text(article), scrape.Attr(article, "href"))
}
}
开发者ID:jmonmane,项目名称:scrape,代码行数:29,代码来源:main.go
示例2: Scrape
// Scrape scrapes a site for a keyword
func (q *query) Scrape() []*match {
// Request the URL
resp, err := http.Get(q.SiteURL)
if err != nil {
panic(err)
log.Fatal("Couldn't GET ", q.SiteURL)
}
// Parse the contents of the URL
root, err := html.Parse(resp.Body)
if err != nil {
panic(err)
log.Fatal("Unable to parse response")
}
// Grab all the posts and print them
posts := scrape.FindAll(root, scrape.ByClass("description"))
matches := make([]*match, len(posts))
for i, post := range posts {
matches[i] = &match{
Title: scrape.Text(post.FirstChild.NextSibling),
Description: scrape.Text(post),
Link: "http://kijiji.ca" + scrape.Attr(post.FirstChild.NextSibling, "href"),
Price: scrape.Text(post.NextSibling.NextSibling),
Matched: false,
}
}
return matches
}
开发者ID:bentranter,项目名称:kijiji-scrape,代码行数:32,代码来源:main.go
示例3: parseBroadcastURLsNode
func (day *timeURL) parseBroadcastURLsNode(root *html.Node) (ret []*broadcastURL, err error) {
const closeDownHour int = 5
for _, h4 := range scrape.FindAll(root, func(n *html.Node) bool { return atom.H4 == n.DataAtom }) {
year, month, day_, err := timeForH4(scrape.Text(h4), &day.Time)
if nil != err {
panic(err)
}
// fmt.Printf("%d-%d-%d %s\n", year, month, day, err)
for _, a := range scrape.FindAll(h4.Parent, func(n *html.Node) bool { return atom.A == n.DataAtom && atom.Dt == n.Parent.DataAtom }) {
m := hourMinuteTitleRegExp.FindStringSubmatch(scrape.Text(a))
if nil == m {
panic(errors.New("Couldn't parse <a>"))
}
ur, _ := url.Parse(scrape.Attr(a, "href"))
hour := r.MustParseInt(m[1])
dayOffset := 0
if hour < closeDownHour {
dayOffset = 1
}
// fmt.Printf("%s %s\n", b.r.TimeURL.String(), b.Title)
bcu := broadcastURL(r.BroadcastURL{
TimeURL: r.TimeURL{
Time: time.Date(year, month, day_+dayOffset, hour, r.MustParseInt(m[2]), 0, 0, localLoc),
Source: *day.Source.ResolveReference(ur),
Station: day.Station,
},
Title: strings.TrimSpace(m[3]),
})
ret = append(ret, &bcu)
}
}
return
}
开发者ID:mro,项目名称:internet-radio-recorder,代码行数:33,代码来源:br.go
示例4: parseBroadcastsFromNode
func (day *timeURL) parseBroadcastsFromNode(root *html.Node) (ret []*r.Broadcast, err error) {
nodes := scrape.FindAll(root, func(n *html.Node) bool { return atom.Div == n.DataAtom && "time" == scrape.Attr(n, "class") })
ret = make([]*r.Broadcast, len(nodes))
for index, tim := range nodes {
// prepare response
bc := r.Broadcast{
BroadcastURL: r.BroadcastURL{
TimeURL: r.TimeURL(*day),
},
}
// some defaults
bc.Language = &lang_de
bc.Publisher = &publisher
// set start time
{
div_t := strings.TrimSpace(scrape.Text(tim))
if 5 != len(div_t) {
continue
}
hour := r.MustParseInt(div_t[0:2])
minute := r.MustParseInt(div_t[3:5])
bc.Time = time.Date(day.Year(), day.Month(), day.Day(), hour, minute, 0, 0, day.TimeZone)
if index > 0 {
ret[index-1].DtEnd = &bc.Time
}
}
for _, tit := range scrape.FindAll(tim.Parent, func(n *html.Node) bool {
return atom.A == n.DataAtom && atom.Div == n.Parent.DataAtom && "descr" == scrape.Attr(n.Parent, "class")
}) {
// Title
bc.Title = strings.TrimSpace(scrape.Text(tit))
href := scrape.Attr(tit, "href")
if "" != href {
u, _ := url.Parse(href)
bc.Subject = day.Source.ResolveReference(u)
}
desc_node := tit.Parent
desc_node.RemoveChild(tit)
description := r.TextWithBrFromNodeSet([]*html.Node{desc_node})
bc.Description = &description
// fmt.Fprintf(os.Stderr, "\n")
}
ret[index] = &bc
}
// fmt.Fprintf(os.Stderr, "len(ret) = %d '%s'\n", len(ret), day.Source.String())
if len(nodes) > 0 {
midnight := time.Date(day.Year(), day.Month(), day.Day(), 24, 0, 0, 0, day.TimeZone)
ret[len(nodes)-1].DtEnd = &midnight
}
return
}
开发者ID:mro,项目名称:internet-radio-recorder,代码行数:52,代码来源:m945.go
示例5: NewListing
func NewListing(ctx appengine.Context, url string) (*Listing, error) {
client := urlfetch.Client(ctx)
resp, err := client.Get("http://167.88.16.61:2138/" + url)
if err != nil {
ctx.Errorf("%s", err)
}
ctx.Debugf("Craigslist request came back with status: %s", resp.Status)
if err != nil {
ctx.Errorf("%s", err)
return nil, errors.New("Get listing failed")
}
root, err := html.Parse(resp.Body)
if err != nil {
ctx.Errorf("%s", "Parsing Error")
return nil, errors.New("Parse body failed")
}
title, ok := scrape.Find(root, scrape.ByTag(atom.Title))
if !ok {
ctx.Errorf("%s", "Error getting title")
return nil, errors.New("Get title failed")
}
price, ok := scrape.Find(root, scrape.ByClass("price"))
if !ok {
ctx.Errorf("%s", "Error getting price")
return nil, errors.New("Get price failed")
}
intPrice, err := strconv.Atoi(scrape.Text(price)[1:])
if err != nil {
ctx.Errorf("Error casting price: %s", scrape.Text(price))
return nil, err
}
images := scrape.FindAll(root, scrape.ByTag(atom.Img))
imageUrl := ""
for _, image := range images {
if scrape.Attr(image, "title") == "image 1" {
imageUrl = scrape.Attr(image, "src")
}
}
ctx.Debugf("Craigslist returned listing.Price: %d, listing.Title: %s", intPrice, scrape.Text(title))
return &Listing{
Url: url,
Title: scrape.Text(title),
Price: intPrice,
ImageUrl: imageUrl,
}, nil
}
开发者ID:matthewdu,项目名称:powerplug,代码行数:49,代码来源:craigslist.go
示例6: ParseRecord
func ParseRecord(n *html.Node) Torrent {
tds := scrape.FindAll(n, scrape.ByTag(atom.Td))
var size, uptime, uploader string
if len(tds) == 4 {
cat := scrape.Text(tds[0])[0:3]
name, magnet, desc := ParseName(tds[1])
matches := re.FindStringSubmatch(desc)
uptime, size, uploader = matches[1], matches[2], matches[3]
seed := scrape.Text(tds[2])
leech := scrape.Text(tds[3])
return Torrent{cat, name, magnet, size, uptime, uploader, seed, leech}
} else {
fmt.Println("Error: not expected format")
}
return Torrent{}
}
开发者ID:anykao,项目名称:p,代码行数:16,代码来源:main.go
示例7: main
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"))
}
}
开发者ID:abejenaru,项目名称:vagrant-boxes,代码行数:25,代码来源:first.go
示例8: fillJobStruct
func fillJobStruct(n *html.Node) *Job {
job := new(Job)
job.Title = scrape.Text(n)
job.RetriveOn = time.Now().Format(time.RFC822Z)
job.url = jobUrl(n)
fmt.Println(job.url)
job.ID = jobID(job.url)
job.EmailFormLink = jobEmailFromUrl + job.ID
jp := fetchByID(job.ID)
job.jobPage = jp
desc, _ := scrape.Find(job.jobPage, descriptionMatcher)
job.Description = scrape.Text(desc)
req, _ := scrape.Find(job.jobPage, requiermentMatcher)
job.Requierments = scrape.Text(req)
return job
}
开发者ID:gozes,项目名称:co,代码行数:17,代码来源:co.go
示例9: parsepost
func parsepost(n *html.Node) Post {
post := Post{}
// get the title. uses a scrape inbuilt matcher
title_scrape, _ := scrape.Find(n, scrape.ByClass("title"))
title := scrape.Text(title_scrape.FirstChild)
// get the subreddit. This requires a custom matcher.
matcher := func(n *html.Node) bool {
if n.DataAtom == atom.A && n.Parent != nil {
return scrape.Attr(n, "class") == "subreddit hover may-blank"
}
return false
}
sub, _ := scrape.Find(n, matcher)
subreddit := scrape.Text(sub)
// get the url to the comments. requires custom matcher.
matcher = func(n *html.Node) bool {
if n.DataAtom == atom.Ul && n.FirstChild != nil {
return scrape.Attr(n, "class") == "flat-list buttons" && scrape.Attr(n.FirstChild, "class") == "first"
}
return false
}
ul, _ := scrape.Find(n, matcher) // ul is a list of two buttons: one that links to a post's comments page, one a "share" function
li := ul.FirstChild // the first list item of ul -- this will always be the comments page link.
url := scrape.Attr(li.FirstChild, "href") // finally, the url found in the list item.
// get the author. Uses custom matcher and magic.
matcher = func(n *html.Node) bool {
if n.DataAtom == atom.A && n.Parent.DataAtom == atom.P {
return strings.Contains(scrape.Attr(n, "href"), "/user/")
}
return false
}
author_scrape, _ := scrape.Find(n, matcher)
author := scrape.Text(author_scrape)
post.title = title
post.subreddit = subreddit
post.url = url
post.author = author
return post
}
开发者ID:jalavosus,项目名称:redditscraper,代码行数:45,代码来源:reddit_scraper.go
示例10: findHTMLTitle
func findHTMLTitle(doc *html.Node) string {
el, found := scrape.Find(doc, scrape.ByTag(atom.Title))
if !found {
return ""
}
return scrape.Text(el)
}
开发者ID:mcmillan,项目名称:socialite,代码行数:9,代码来源:title.go
示例11: Get
// Get devuelve el conjunto de tiempos de llegada para los buses de la parada
// dada. Hay que comprobar que no se devuelve error.
func Get(parada int) (TiemposParada, error) {
resp, err := http.Get("http://www.auvasa.es/paradamb.asp?codigo=" +
strconv.Itoa(parada))
if err != nil {
return TiemposParada{}, errors.New("Error al conectar con el servidor de AUVASA.")
}
rInUTF8 := transform.NewReader(resp.Body, charmap.Windows1252.NewDecoder())
root, err := html.Parse(rInUTF8)
if err != nil {
return TiemposParada{}, errors.New("Error en la respuesta de AUVASA.")
}
headers := scrape.FindAll(root, scrape.ByTag(atom.H1))
if len(headers) < 2 {
return TiemposParada{}, errors.New("La parada indicada parece errónea.")
}
lineasTiempos := scrape.FindAll(root, scrape.ByClass("style36"))
resultados := make([]ProximoBus, len(lineasTiempos))
for i, item := range lineasTiempos {
valores := scrape.FindAll(item, scrape.ByClass("style38"))
resultados[i] = ProximoBus{
Linea: scrape.Text(valores[0]),
Destino: scrape.Text(valores[2]),
Minutos: scrape.Text(valores[3]),
}
}
if len(resultados) == 0 {
return TiemposParada{}, errors.New("No hay tiempos para la parada especificada. Puede que sea errónea o que ya no haya buses.")
}
return TiemposParada{
Nombre: scrape.Text(headers[1]),
Tiempos: resultados,
Momento: time.Now(),
Codigo: parada,
}, nil
}
开发者ID:adrm,项目名称:auvasa,代码行数:43,代码来源:auvasa.go
示例12: TweetsToUser
func TweetsToUser(u user.User) []tweet.Tweet {
reqURL := SearchURL
_url.SetQueryParams(&reqURL, map[string]string{
"q": "to:" + u.ScreenName,
"f": "tweets",
})
res, err := http.Get(reqURL.String())
PanicIf(err)
root, err := html.Parse(res.Body)
PanicIf(err)
tweetsMatcher := func(n *html.Node) bool {
return n.DataAtom == atom.Div && strings.HasPrefix(scrape.Attr(n, "class"), "tweet original-tweet")
}
tweetScreenNameMatcher := func(n *html.Node) bool {
return n.DataAtom == atom.Span && strings.HasPrefix(scrape.Attr(n, "class"), "username")
}
tweetTextMatcher := func(n *html.Node) bool {
return n.DataAtom == atom.P && strings.HasSuffix(scrape.Attr(n, "class"), "tweet-text")
}
tweetNodes := scrape.FindAll(root, tweetsMatcher)
tweets := make([]tweet.Tweet, len(tweetNodes))
for i, n := range tweetNodes {
t := tweet.Tweet{
ID: scrape.Attr(n, "data-user-id"),
}
if child, ok := scrape.Find(n, tweetScreenNameMatcher); ok {
t.Author = *user.NewUser(scrape.Text(child))
}
if child, ok := scrape.Find(n, tweetTextMatcher); ok {
t.Text = scrape.Text(child)
}
tweets[i] = t
}
return tweets
}
开发者ID:mrap,项目名称:twitterget,代码行数:39,代码来源:search.go
示例13: ParseName
func ParseName(n *html.Node) (string, string, string) {
matcher := func(n *html.Node) bool {
// must check for nil values
if n.DataAtom == atom.A && n.Parent.DataAtom == atom.Td {
return true
}
return false
}
var name, magnet, desc string
if detName, ok := scrape.Find(n, scrape.ByClass("detName")); ok {
name = scrape.Text(detName)
}
if anchor, ok := scrape.Find(n, matcher); ok {
magnet = scrape.Attr(anchor, "href")
}
if detDesc, ok := scrape.Find(n, scrape.ByClass("detDesc")); ok {
desc = scrape.Text(detDesc)
}
return name, magnet, desc
}
开发者ID:anykao,项目名称:p,代码行数:22,代码来源:main.go
示例14: parseVideoInfo
func parseVideoInfo(element *html.Node) *YoutubeVideoInfo {
var info YoutubeVideoInfo
info.ID = scrape.Attr(element, "data-context-item-id")
thumbnailContainer, ok := scrape.Find(element, scrape.ByClass("yt-thumb-simple"))
if ok {
thumbnailImage, ok := scrape.Find(thumbnailContainer, scrape.ByTag(atom.Img))
if ok {
info.ThumbnailURL, _ = url.Parse(scrape.Attr(thumbnailImage, "src"))
}
}
videoTimeElement, ok := scrape.Find(element, scrape.ByClass("video-time"))
if ok {
durationStr := strings.TrimSpace(scrape.Text(videoTimeElement))
info.Length, _ = parseVideoDuration(durationStr)
}
linkFieldClasses := []string{"yt-lockup-title", "yt-lockup-byline"}
linkFieldPtrs := []*string{&info.Title, &info.Author}
for i, class := range linkFieldClasses {
linkContainer, ok := scrape.Find(element, scrape.ByClass(class))
if ok {
link, ok := scrape.Find(linkContainer, scrape.ByTag(atom.A))
if ok {
*linkFieldPtrs[i] = strings.TrimSpace(scrape.Text(link))
}
}
}
descBox, ok := scrape.Find(element, scrape.ByClass("yt-lockup-description"))
if ok {
info.Description = strings.TrimSpace(scrape.Text(descBox))
}
return &info
}
开发者ID:unixpickle,项目名称:gscrape,代码行数:38,代码来源:youtube.go
示例15: resolveUrl
func resolveUrl(website string) string {
site := getURL(website)
contents, err := html.Parse(site.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
panic(err)
}
title, _ := scrape.Find(contents, scrape.ByTag(atom.Title))
var titulo string = scrape.Text(title)
return titulo
}
开发者ID:ChrisFernandez,项目名称:GoBot,代码行数:14,代码来源:gobot.go
示例16: queryWikipedia
func queryWikipedia(word string) string {
word = strings.TrimSpace(word)
website := "http://en.wikipedia.com/wiki/" + word
site := getURL(website)
contents, err := html.Parse(site.Body)
if err != nil {
fmt.Print("%s", err)
panic(err)
os.Exit(1)
}
intro, _ := scrape.Find(contents, scrape.ByTag(atom.P))
var resp string = scrape.Text(intro)
return resp
}
开发者ID:ChrisFernandez,项目名称:GoBot,代码行数:15,代码来源:gobot.go
示例17: parseServerStatus
// parseServerStatus returns a slice of strings containing only server stats.
func parseServerStatus(root *html.Node) []string {
var apacheStats []string
// Lines with stats start with a number.
var validStats = regexp.MustCompile(`^[0-9]`)
// Grab all the table rows.
rows := scrape.FindAll(root, scrape.ByTag(atom.Tr))
// If each row matches - add it to the stats lines.
for _, row := range rows {
content := scrape.Text(row)
if validStats.MatchString(content) {
apacheStats = append(apacheStats, content)
}
}
Log(fmt.Sprintf("parseServerStatus apacheStats='%d'", len(apacheStats)), "debug")
return apacheStats
}
开发者ID:darron,项目名称:goshe,代码行数:17,代码来源:apache.go
示例18: eventDetailsToStrArr
func eventDetailsToStrArr(eventDetails []*html.Node, eventID int) []string {
return []string{
strconv.Itoa(eventID),
scrape.Text(eventDetails[0]),
scrape.Text(eventDetails[1]),
scrape.Text(eventDetails[2]),
scrape.Text(eventDetails[3]),
scrape.Text(eventDetails[4]),
scrape.Text(eventDetails[5]),
strings.TrimPrefix(
scrape.Attr(eventDetails[5].FirstChild, "href"),
"mailto:"),
}
}
开发者ID:jamesma,项目名称:html-scraper,代码行数:14,代码来源:chamberorganizer.go
示例19: scraper
func scraper() {
fd, err := os.Open("/mnt/hgfs/Downloads/wiki.html")
if err != nil {
panic(err)
}
defer fd.Close()
root, err := html.Parse(fd)
if err != nil {
panic(err)
}
t := html.NewTokenizer(root)
// matcher := func(n *html.Node) bool {
// if n.DataAtom == atom.Table {
// return true
// }
// return false
// }
// rowMatcher := func(n *html.Node) bool {
// if n.DataAtom == atom.Tr {
// return true
// }
// return false
// }
tableMatcher := scrape.ById(tableID)
table := scrape.FindAll(root, tableMatcher)
for _, v := range table {
if t.Token().Data == "tr" {
fmt.Printf("%s\n", scrape.Text(v))
} else {
t.Next()
}
}
// for , v := range table {
// fmt.Printf("%s\n", scrape.Text(v))
// }
}
开发者ID:jmonmane,项目名称:golang,代码行数:41,代码来源:main.go
示例20: login
func login() {
client := &http.Client{}
// POST /ajax/login.html HTTP/1.1
// Host: learn.infiniteskills.com
// Connection: close
// Content-Length: 64
// Cache-Control: max-age=0
// Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
// Origin: https://learn.infiniteskills.com
// Upgrade-Insecure-Requests: 1
// User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36
// Content-Type: application/x-www-form-urlencoded
// Referer: https://learn.infiniteskills.com/login.html
// Accept-Encoding: gzip, deflate
// Accept-Language: en-US,en;q=0.8
// Cookie: is_learn=YmVhdWdhbGJyYWl0aA%3D%3D; iskillslearn=14532496193884
//
// username=beaugalbraith&password=+divxfactory-btcob5&remember=yes
req, err := http.NewRequest("POST", "https://learn.infiniteskills.com/ajax/login.html", nil)
cookie := http.Cookie{
Name: "username",
Value: "beaugalbraith",
Name: "password",
Value: " divxfactory-btcob5",
}
req.AddCookie(&cookie)
req.Header.Set("User-Agent", ua)
resp, err := client.Do(req)
if err != nil {
panic(err)
}
root, err := html.Parse(resp.Body)
if err != nil {
panic(err)
}
fmt.Printf("%s", resp.Header)
defer resp.Body.Close()
fmt.Printf("%s", scrape.Text(root))
}
开发者ID:jmonmane,项目名称:golang,代码行数:41,代码来源:main.go
注:本文中的github.com/yhat/scrape.Text函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论