我想下载幻想足球数据以在Go中进行分析,但是当我尝试从此api页面下载时,即使代码适用于其他网站(例如此api页面),我仍返回一个空响应
最小复制,输出一个空数组。
package main
import (
"fmt"
"io/ioutil"
"net/http"
"time"
)
const AllPlayerData = "https://fantasy.premierleague.com/drf/bootstrap-static"
func main() {
downloadAllData()
}
func downloadAllData() {
client := &http.Client{
Timeout: 20 * time.Second,
}
response, err := client.Get(AllPlayerData)
if err != nil {
fmt.Println("Unable to download player data.")
return
}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Println("Failed to read response")
return
}
defer response.Body.Close()
fmt.Println(body)
}
相同的网页在Python中可以正常下载:
import requests
url = "https://fantasy.premierleague.com/drf/bootstrap-static"
r = requests.get(url)
print(r.content)
我认为这与例如Ajax调用无关,因为在Chrome浏览器中查看网络请求不会超出页面加载本身
相关分类