小编Ake*_*eem的帖子

使用 Go 解析 HTML

我正在尝试使用 Go 构建一个网络爬虫,我对这门语言相当陌生,我不确定在使用 html 解析器时我做错了什么。我正在尝试解析 html 以查找锚标记,但我不断收到 html.TokenTypeEnd 。

package main

import (
    "fmt"
    "golang.org/x/net/html"
    "io/ioutil"
    "net/http"
)

func GetHtml(url string) (text string, resp *http.Response, err error) {
    var bytes []byte
    if url == "https://www.coastal.edu/scs/employee" {
        resp, err = http.Get(url)
        if err != nil {
            fmt.Println("There seems to ben an error with the Employee Console.")
        }
        bytes, err = ioutil.ReadAll(resp.Body)
        if err != nil {
            fmt.Println("Cannot read byte response from Employee Console.")
        }
        text = string(bytes)
    } else {
        fmt.Println("Issue …
Run Code Online (Sandbox Code Playgroud)

html go html-parsing web-scraping

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

go ×1

html ×1

html-parsing ×1

web-scraping ×1