質問編集履歴

3

編集

2021/01/13 07:35

投稿

pokerStars
pokerStars

スコア67

test CHANGED
File without changes
test CHANGED
@@ -94,7 +94,7 @@
94
94
 
95
95
 
96
96
 
97
- func AnytimeDisplayAction(c *gin.Context){
97
+ func DisplayAction(c *gin.Context){
98
98
 
99
99
  const url = "https://ja.wikipedia.org/wiki/SCADA"
100
100
 

2

編集

2021/01/13 07:35

投稿

pokerStars
pokerStars

スコア67

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  ```go
2
2
 
3
- func AnytimeDisplayAction(c *gin.Context){
3
+ func DisplayAction(c *gin.Context){
4
4
 
5
5
  const url = "https://ja.wikipedia.org/wiki/SCADA"
6
6
 

1

追記

2021/01/13 07:35

投稿

pokerStars
pokerStars

スコア67

test CHANGED
File without changes
test CHANGED
@@ -77,3 +77,67 @@
77
77
  文字化けされてしまいます。goqueryを使う際に上記画像のような文字化けを起こさないようにするにはどうすればよいでしょうか?
78
78
 
79
79
  何卒よろしくお願い致します。
80
+
81
+
82
+
83
+ **他に試したこと**
84
+
85
+ ```go
86
+
87
+ import(
88
+
89
+ 他省略
90
+
91
+ "golang.org/x/text/encoding/japanese"
92
+
93
+ "golang.org/x/text/transform")
94
+
95
+
96
+
97
+ func AnytimeDisplayAction(c *gin.Context){
98
+
99
+ const url = "https://ja.wikipedia.org/wiki/SCADA"
100
+
101
+
102
+
103
+ res, err := http.Get(url)
104
+
105
+ if err != nil {
106
+
107
+ log.Println(err)
108
+
109
+ }
110
+
111
+ defer res.Body.Close()
112
+
113
+
114
+
115
+ utfBody := transform.NewReader(bufio.NewReader(res.Body), japanese.ShiftJIS.NewDecoder())
116
+
117
+
118
+
119
+
120
+
121
+ doc, _ := goquery.NewDocumentFromReader(reader)
122
+
123
+ text := doc.Find(".mw-headline").Each(func(i int, s *goquery.Selection) {
124
+
125
+ s.Text()
126
+
127
+ })
128
+
129
+
130
+
131
+
132
+
133
+ c.HTML(200, "test.html", gin.H{
134
+
135
+ "title1": text,
136
+
137
+
138
+
139
+ })
140
+
141
+ }
142
+
143
+ ```