figured out goquery
This commit is contained in:
parent
588d0e1833
commit
74dfcc4266
35
main.go
35
main.go
@ -5,6 +5,7 @@ import (
|
||||
"federated.computer/wp-sync-slowtwitch/services/slowtwitch"
|
||||
"fmt"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"golang.org/x/net/html"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
@ -51,17 +52,45 @@ func main() {
|
||||
log.Fatalf("goquery.NewDocumentFromReader -> %v", err)
|
||||
}
|
||||
// Find all image tags and extract their 'src' attributes
|
||||
var imagePaths []string
|
||||
doc.Find(".detail_text img").Each(func(i int, img *goquery.Selection) {
|
||||
imgUrl, exists := img.Attr("src")
|
||||
if exists {
|
||||
log.Printf("Image URL %d: %s", i+1, slowtwitch.GetURL(imgUrl))
|
||||
imagePaths = append(imagePaths, imgUrl)
|
||||
}
|
||||
})
|
||||
blog, err := doc.Find(".detail_text").Html()
|
||||
blog := doc.Find(".detail_text")
|
||||
blog.Find(":first-child").Remove()
|
||||
blog.Find("img").Each(func(i int, img *goquery.Selection) {
|
||||
imgUrl, exists := img.Attr("src")
|
||||
if exists {
|
||||
newEle := goquery.NewDocumentFromNode(&html.Node{
|
||||
Type: html.ElementNode,
|
||||
Data: "img",
|
||||
Attr: []html.Attribute{
|
||||
html.Attribute{
|
||||
Key: "src",
|
||||
Val: "www.slowtwitch.cloud" + imgUrl,
|
||||
},
|
||||
html.Attribute{
|
||||
Key: "class",
|
||||
Val: "class1 class2 class3",
|
||||
},
|
||||
},
|
||||
})
|
||||
img.AfterSelection(newEle.Selection)
|
||||
}
|
||||
|
||||
img.Remove()
|
||||
})
|
||||
blogContent, err := blog.Html()
|
||||
if err != nil {
|
||||
log.Fatalf("goquery.NewDocumentFromReader -> %v", err)
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println(blog)
|
||||
fmt.Println(blogContent)
|
||||
//First image in list will be the featured image, remove that img tag from the returned html
|
||||
//images will need their src updated after upload
|
||||
//EXPERIMENT END
|
||||
editorMigration := migration.MigrateAuthors{
|
||||
SlowtwitchDatabase: slowtwitchDB,
|
||||
|
Loading…
Reference in New Issue
Block a user