You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.1 KiB
58 lines
1.1 KiB
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
)
|
|
|
|
func main() {
|
|
db, err := sql.Open("mysql", "root:liunian@2021@tcp(192.168.31.146:3306)/entertainment_new")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer db.Close()
|
|
|
|
rows, err := db.Query("SELECT content FROM t_infor")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer rows.Close()
|
|
|
|
host := "http://192.168.31.146"
|
|
|
|
re := regexp.MustCompile(`<img.*?src="(.*?)"`)
|
|
|
|
for rows.Next() {
|
|
var content string
|
|
err := rows.Scan(&content)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
matches := re.FindAllStringSubmatch(content, -1)
|
|
var images []string
|
|
for _, match := range matches {
|
|
images = append(images, match[1])
|
|
}
|
|
|
|
if len(images) == 0 {
|
|
continue
|
|
}
|
|
insertStmt := "UPDATE t_infor SET large_img = ? WHERE classify_id != 95 and content = ?"
|
|
i := strings.Replace(images[0], host, "", -1)
|
|
_, err = db.Exec(insertStmt, i, content)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
if err := rows.Err(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fmt.Println("Images extracted successfully")
|
|
}
|