Answer the question
In order to leave comments, you need to log in
How to determine the type of a variable in Golang?
I am new to Go. and I ran into such a problem:
I take the site address from the database (postgerysql) and try to parse it, but it doesn’t work. when I specify a variable with the same site address in the code (variable), then everything works. the address is stored in the character(255) column in the database. for the parser I use github.com/PuerkitoBio/goquery
Answer the question
In order to leave comments, you need to log in
package main
import (
"fmt"
"database/sql"
_ "github.com/lib/pq"
"log"
"github.com/PuerkitoBio/goquery"
)
type SaitsInfo struct {
s_url,s_name,s_block string
}
func (this SaitsInfo) view(){
doc, err := goquery.NewDocument(this.s_url)
if err != nil {
log.Fatal(err)
}
doc.Find(".offers_box_table tr .txt_box2").Each(func(i int, s *goquery.Selection){
band := s.Find("a").Text()
title := s.Find("span").Text()
fmt.Printf("Review %d: %s - %s\n", i, band, title)
})
}
var (
url string
name string
block string
)
func main() {
db, err := sql.Open("postgres", "данные подключения")
if err != nil {
log.Fatal(err)
}
saits, err := db.Query(`SELECT url,name,block FROM saits`)
if err != nil {
log.Fatal(err)
}
for saits.Next(){
if err := saits.Scan(&url,&name,&block); err != nil{
log.Fatal(err)
}
si := SaitsInfo{url, name, block}
si.view()
}
defer db.Close()
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question