Skip to content

Commit

Permalink
improved xkcd example
Browse files Browse the repository at this point in the history
  • Loading branch information
anaskhan96 committed Oct 7, 2017
1 parent 99230ad commit 7a8d31f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions examples/xkcdextract/xkcdextract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package main

import (
"fmt"

"github.com/anaskhan96/soup"
)

func main() {
fmt.Println("Enter the url of the xkcd comic :")
var url string
fmt.Scanf("%s", &url)
fmt.Println("Enter the xkcd comic number :")
var num int
fmt.Scanf("%d", &num)
url := fmt.Sprintf("https://xkcd.com/%d", num)
resp, _ := soup.Get(url)
doc := soup.HTMLParse(resp)
title := doc.Find("div", "id", "ctitle").Text()
Expand All @@ -19,8 +21,8 @@ func main() {
}

/* --- Console I/O ---
Enter the url of the xkcd comic :
https://xkcd.com/353
Enter the xkcd comic number :
353
Title of the comic : Python
Source of the image : //imgs.xkcd.com/comics/python.png
Underlying text of the image : I wrote 20 short programs in Python yesterday. It was wonderful. Perl, I'm leaving you.
Expand Down

0 comments on commit 7a8d31f

Please sign in to comment.