Skip to content

Instantly share code, notes, and snippets.

@hanksudo
Last active January 29, 2016 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanksudo/f9d096ce48a8f8218815 to your computer and use it in GitHub Desktop.
Save hanksudo/f9d096ce48a8f8218815 to your computer and use it in GitHub Desktop.
Grab origin image url from Instagram / Facebook
package main
import (
"fmt"
"log"
"net/http"
"github.com/PuerkitoBio/goquery"
)
func main() {
res, err := http.Get("https://www.instagram.com/p/BACozJ6kUhc/?taken-by=hanksudo")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
doc, err := goquery.NewDocumentFromReader(res.Body)
if err != nil {
log.Fatal(err)
}
doc.Find("meta[property=\"og:image\"]").Each(func(i int, s *goquery.Selection) {
originImageUrl, _ := s.Attr("content")
exts := []string{"", ".txt", ".html"}
for _, ext := range exts {
fmt.Println(originImageUrl + ext)
}
})
}
# -*- coding: utf-8 -*-
#
# $ pip install pyquery
#
from pyquery import PyQuery
url = "https://www.instagram.com/p/BACozJ6kUhc/?taken-by=hanksudo"
d = PyQuery(url)
origin_image_url = d('meta[property="og:image"]').attr("content").encode("utf-8")
for ext in ("", ".txt", ".html"):
print "{}{}".format(origin_image_url, ext)