Last active
January 29, 2016 07:20
-
-
Save hanksudo/f9d096ce48a8f8218815 to your computer and use it in GitHub Desktop.
Grab origin image url from Instagram / Facebook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://scontent-tpe1-1.cdninstagram.com/t51.2885-15/e35/918196_1002565209806234_824172105_n.jpg
https://scontent-tpe1-1.cdninstagram.com/t51.2885-15/e35/918196_1002565209806234_824172105_n.jpg.txt
https://scontent-tpe1-1.cdninstagram.com/t51.2885-15/e35/918196_1002565209806234_824172105_n.jpg.html