Last active
August 29, 2015 14:11
-
-
Save 7yan00/d0da45c6649da6a4702d to your computer and use it in GitHub Desktop.
hoge01.go
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" | |
"github.com/PuerkitoBio/goquery" | |
"net/url" | |
) | |
func GetPage(base string) { | |
doc, _ := goquery.NewDocument(base) | |
doc.Find("img").Each(func(_ int, s *goquery.Selection) { | |
target, _ := s.Attr("src") | |
base, _ := url.Parse("http://blog.golang.org/") | |
targets, _ := url.Parse(target) | |
fmt.Println(base.ResolveReference(targets)) | |
}) | |
} | |
func main() { | |
base := "http://blog.golang.org/" | |
GetPage(base) | |
} |
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
import ( | |
"io" | |
"net/http" | |
"os" | |
) | |
func main() { | |
var url string = "http://blog.golang.org/5years/gophers5th.jpg" | |
response, err := http.Get(url) | |
if err != nil { | |
panic(err) | |
} | |
defer response.Body.Close() | |
file, err := os.Create("gopher.jpg") | |
if err != nil { | |
panic(err) | |
} | |
defer file.Close() | |
io.Copy(file, response.Body) | |
} |
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 ( | |
"bufio" | |
"fmt" | |
"os" | |
) | |
func main() { | |
var unko string = "otinpo" | |
scanner := bufio.NewScanner(os.Stdin) | |
for scanner.Scan() { | |
fmt.Println(unko) | |
} | |
if err := scanner.Err(); err != nil { | |
fmt.Fprintln(os.Stderr, "reading standard input:", err) | |
} | |
} |
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" | |
"github.com/PuerkitoBio/goquery" | |
"os" | |
"bufio" | |
) | |
var url2 string = "" | |
func GetPage(_url string) { | |
doc, _ := goquery.NewDocument(_url) | |
doc.Find("img").Each(func(_ int, s *goquery.Selection) { | |
url2, _ := s.Attr("src") | |
fmt.Println(url2) | |
}) | |
} | |
func main() { | |
_url := "http://blog.golang.org/" | |
GetPage(_url) | |
scanner := bufio.NewScanner(os.Stdin) | |
for scanner.Scan() { | |
fmt.Println(_url + url2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment