Skip to content

Commit 7a8d31f

Browse files
committed
improved xkcd example
1 parent 99230ad commit 7a8d31f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

examples/xkcdextract/xkcdextract.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package main
22

33
import (
44
"fmt"
5+
56
"github.com/anaskhan96/soup"
67
)
78

89
func main() {
9-
fmt.Println("Enter the url of the xkcd comic :")
10-
var url string
11-
fmt.Scanf("%s", &url)
10+
fmt.Println("Enter the xkcd comic number :")
11+
var num int
12+
fmt.Scanf("%d", &num)
13+
url := fmt.Sprintf("https://xkcd.com/%d", num)
1214
resp, _ := soup.Get(url)
1315
doc := soup.HTMLParse(resp)
1416
title := doc.Find("div", "id", "ctitle").Text()
@@ -19,8 +21,8 @@ func main() {
1921
}
2022

2123
/* --- Console I/O ---
22-
Enter the url of the xkcd comic :
23-
https://xkcd.com/353
24+
Enter the xkcd comic number :
25+
353
2426
Title of the comic : Python
2527
Source of the image : //imgs.xkcd.com/comics/python.png
2628
Underlying text of the image : I wrote 20 short programs in Python yesterday. It was wonderful. Perl, I'm leaving you.

0 commit comments

Comments
 (0)