在Golang中从HTML中提取文本内容

 被撑死的猫。。。 发布于 2023-02-05 10:21

在Golang中从字符串中提取内部子串的最佳方法是什么?

输入:

"Hello 

this is paragraph

this is junk

this is paragraph 2

this is junk 2"

输出:

"this is paragraph \n
 this is paragraph 2"

是否有任何字符串包/库已经做了类似的事情?

package main

import (
    "fmt"
    "strings"
)

func main() {
    longString := "Hello world 

this is paragraph

this is junk

this is paragraph 2

this is junk 2" newString := getInnerStrings("

", "

", longString) fmt.Println(newString) //output: this is paragraph \n // this is paragraph 2 } func getInnerStrings(start, end, str string) string { //Brain Freeze //Regex? //Bytes Loop? }

谢谢

1 个回答
  • 不要使用正则表达式来尝试和解释HTML.使用功能齐全的HTML标记生成器和解析器.

    我建议你阅读关于CodingHorror的这篇文章.

    2023-02-05 10:25 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有