Golang(8)-goquery库的使用

Go语言 简单爬虫 goquery : https://github.com/PuerkitoBio/goquery首先,在这里介绍使用一个叫goquery的包,这个是go语言写爬虫非常好用的一个包,包含了网络连接和元素处理等。先来试试go get github.com/Puerkito/goquery如何从github.com下载与配置包已经在之前的文档中解释: Git指令使用现在发现,这里无法get这个包,提示的... 阅读详情


更多关于Golang核心编程知识的文章请看:Golang核心编程(0)-目录页


goquery是golang的一个爬虫常用第三方库,它主要的作用是处理html文档,将其我们需要的内容进行筛选处理。goquery是golang领域的jquery,它的使用和jquery的选择器有十分相似,如果你学过jquery,那么将十分容易上手。

一、goquery库的安装

具体的安装方式网上讲得很清楚,但是你可能会遇到以下问题:
报错package golang.org/x/net/websocket: unrecognized import path
原因在于本地缺少一个golang.org/x/net的包,用以下方法可以解决:

https://blog.youkuaiyun.com/qq_31967569/article/details/81060525

二、goquery的使用

网上有两篇文章讲得很清楚,这里就不再讲了,大家可以查阅:

三、爬取优快云首页文章

3.1、需求分析

显示,打开优快云的首页,我们先确定我们需要爬的数据是什么
在这里插入图片描述
这次我打算爬的是首页文章中的文章名、文章地址、文章作者以及阅读数。

3.2、分析当前页面的html文档

右键,查看页面的源代码,并将源代码拷贝到阅读工具中方便阅读,这里我用的是notepad++去分析html文档
在这里插入图片描述

  • 1、首先锁定文章名所在的位置
    在这里插入图片描述

很快可以发现,文章名的外层是一个a标签,而所有的文章数据都以 list_con这个class的方式循环而得,所以,获取文章名的goquery选择器可以这么写:

document.Find("#feedlist_id").Find("div.list_con").Each(func(i int, selection *goquery.Selection) {
		name1 := selection.Find("div.title h2 a")
		fmt.Printf("name is :%v\n",name1.Text())
	})

得出以下结果,成功地获取了所有文章的名字,第一步完成
在这里插入图片描述

  • 2、锁定文章地址位置
    在这里插入图片描述
document.Find("#feedlist_id").Find("div.list_con").Each(func(i int, selection *goquery.Selection) {
		url,_:= selection.Find(".read_num").Find("a").Attr("href")
		fmt.Printf("url is :%v\n",url)
	})

这里锁定了a标签之后,用了Attr方法去获得href属性中的地址值:
在这里插入图片描述

  • 3、锁定文章作者
    在这里插入图片描述
document.Find("#feedlist_id").Find("div.list_con").Each(func(i int, selection *goquery.Selection) {
		author := selection.Find(".name").Find("a")
		fmt.Printf("author is :%v\n",author.Text())
	})

在这里插入图片描述

  • 4、锁定文章阅读数
    在这里插入图片描述
document.Find("#feedlist_id").Find("div.list_con").Each(func(i int, selection *goquery.Selection) {
   	numbers := selection.Find(".read_num").Find("a span.num")
   	fmt.Printf("numbers is :%v\n",numbers.Text())
   })

在这里插入图片描述

四、爬虫完整程序

package main

import (
	"net/http"
	"github.com/PuerkitoBio/goquery"
	"fmt"
	"strings"
)

func main() {
	//获得response
	response, err := http.Get("https://www.youkuaiyun.com/")
	if err != nil{
		return
	}
	//使用goquery解析response响应体获得html文档
	document, err := goquery.NewDocumentFromReader(response.Body)
	if err != nil{
		return
	}
	defer response.Body.Close()
	//开始解析
	 document.Find("#feedlist_id").Find("div.list_con").Each(func(i int, selection *goquery.Selection) {
		name1 := selection.Find("div.title h2 a")
		 url,_:= selection.Find(".read_num").Find("a").Attr("href")
		 author := selection.Find(".name").Find("a")
		 numbers := selection.Find(".read_num").Find("a span.num")

		fmt.Printf("index is :%d|name is :%v|author is :%v|numbers is :%v|url is :%v \n",i,strings.TrimSpace(name1.Text()),strings.TrimSpace(author.Text()),numbers.Text(),strings.TrimSpace(url))
	})
 
}

成功地爬取了优快云首页的文章数据,之后可以将其写入文件中或者数据库中,如需改进性能的话可以改用多协程,有兴趣的朋友可以深入研究!

index is :0|name is :Python爬取抖音APP,竟然只需要十行代码|author is :娇兮心有之|numbers is :2262|url is :https://blog.youkuaiyun.com/qq_40925239/article/details/83786958 
index is :1|name is :千万别做老板最不能容忍的三种人 z|author is :这个也很漂亮|numbers is :1712|url is :https://blog.youkuaiyun.com/hdfghh/article/details/83955147 
index is :2|name is :程序员晒出小学儿子满分作文《我的爸爸》,真实的让人心疼|author is :taya_a|numbers is :1642|url is :https://blog.youkuaiyun.com/taya_a/article/details/83958356 
index is :3|name is :腾讯 阿里 华为的岗位薪资情况概述|author is :小风花|numbers is :2114|url is :https://blog.youkuaiyun.com/hdfyhf/article/details/83931804 
index is :4|name is :震惊,20年开发经验的技术总监不会搭建Java开发环境|author is :Java填坑之路|numbers is :3733|url is :https://blog.youkuaiyun.com/yelvgou9995/article/details/83961061 
index is :5|name is :在操作系统、芯片领域跌倒的中国程序员,如何崛起?|author is :残留的淡影|numbers is :835|url is :https://blog.youkuaiyun.com/weixin_43587861/article/details/83958910 
index is :6|name is :刚写完排序算法,就被开除了…|author is :Java技术栈|numbers is :605|url is :https://blog.youkuaiyun.com/youanyyou/article/details/84026290 
index is :7|name is :有个程序员男友是什么感觉?女网友:连约个会都要处理BUG!|author is :不玩代码的一鸣|numbers is :2051|url is :https://blog.youkuaiyun.com/weixin_43338842/article/details/83932502 
index is :8|name is :程序员吐槽阿里加班文化上班太累,网友:做程序员这也算高强度?|author is :不玩代码的一鸣|numbers is :1502|url is :https://blog.youkuaiyun.com/weixin_43338842/article/details/83932471 
index is :9|name is :sql 存储过程|author is :树叶子hza|numbers is :1712|url is :https://blog.youkuaiyun.com/hza419763578/article/details/83961826 
index is :10|name is :【软件设计师】——总结|author is :邢美玲|numbers is :233|url is :https://blog.youkuaiyun.com/xml1996/article/details/83959290 
index is :11|name is :虚拟机和Docker的最大区别|author is :JerryWangSAP|numbers is :467|url is :https://blog.youkuaiyun.com/i042416/article/details/84034510 
index is :12|name is :快进来看程序员风格的修真小说!|author is :Java填坑之路|numbers is :485|url is :https://blog.youkuaiyun.com/yelvgou9995/article/details/84067063 
index is :13|name is :ORACLE/MYSQL数据库的常用SQL命令|author is :SunJW_2017|numbers is :399|url is :https://blog.youkuaiyun.com/SunJW_2017/article/details/84023425 
index is :14|name is :ERP工程师的职责是什么|author is :这个也很漂亮|numbers is :432|url is :https://blog.youkuaiyun.com/hdfghh/article/details/84059994 
index is :15|name is :springMVC学习心得及手写springMVC简单实现|author is :棒叔叔|numbers is :245|url is :https://blog.youkuaiyun.com/qq_41785135/article/details/83781493 
index is :16|name is :自动化运维一体化|author is :Stestack|numbers is :585|url is :https://blog.youkuaiyun.com/Stestack/article/details/83963083 
index is :17|name is :#程序员式幽默趣图!从高的职业,现实的残酷!|author is :javam16|numbers is :240|url is :https://blog.youkuaiyun.com/javam16/article/details/83957962 
index is :18|name is :Springboot实现用户登录|author is :HOWSUNSHINE|numbers is :421|url is :https://blog.youkuaiyun.com/HOWSUNSHINE/article/details/83988456 
index is :19|name is :多台SQLServer数据实时同步|author is :weixin_37691493|numbers is :296|url is :https://blog.youkuaiyun.com/weixin_37691493/article/details/83960586 
index is :20|name is :一名年薪百万阿里P8架构师写给Java程序员一些建议(架构师必备)|author is :M阿|numbers is :420|url is :https://blog.youkuaiyun.com/yupi1057/article/details/84068697 
index is :21|name is :在 Java 中初始化 List 的五种方法|author is :Java填坑之路|numbers is :310|url is :https://blog.youkuaiyun.com/yelvgou9995/article/details/83933095 
index is :22|name is :徐小平 不做人生规划,你离挨饿只有三天|author is :这个也很漂亮|numbers is :274|url is :https://blog.youkuaiyun.com/hdfghh/article/details/83955208 
index is :23|name is :Spring 的体系结构|author is :mukes|numbers is :180|url is :https://blog.youkuaiyun.com/mukes/article/details/84071658 
index is :24|name is :浅淡XSS跨站脚本攻击的防御方法|author is :白帽梦想家|numbers is :176|url is :https://blog.youkuaiyun.com/sdb5858874/article/details/84033195 
index is :25|name is :是否在公司里 老板叫你做什么 就做什么的总结|author is :牛仔裤新的|numbers is :204|url is :https://blog.youkuaiyun.com/jgfyyfd/article/details/83935051 
index is :26|name is :长相一般的普通程序员怎么找到喜欢程序员的妹子做女友?|author is :北辰丶|numbers is :175|url is :https://blog.youkuaiyun.com/qq_43093708/article/details/83933576 
index is :27|name is :栈的基本函数C++实现|author is :liaolian1|numbers is :154|url is :https://blog.youkuaiyun.com/liaolian1/article/details/84074829 
index is :28|name is :Java并发——阻塞队列|author is :Crazy_CMT|numbers is :168|url is :https://blog.youkuaiyun.com/qq_38386085/article/details/84035841 
用Go来爬虫 goquery使用 应工作内容需求,要爬取两个网站的数据(至于是什么网站,这里就不透露了,哈哈,害怕被发现了封ip),这些数据是定期更新的。由于后端的所有服务都是用go写的,于是不打算用python,还是想用go来完成这个需求,github里搜了下,发现goquery这个爬虫包用的人还挺多的,5000多个star,而且是BSD开源协议,于是毫不犹豫的拿来用了。 首先,go get https://github.co... 阅读详情

相关推荐

go语言 grequests+goquery 简单爬虫,使用多协程并发爬取

/*下载工具*/ package main import ( "fmt" //go语言版本的jquery "github.com/PuerkitoBio/goquery" "os" "sync" "strings" //go语言版本的request "github.com/levigross/grequests" "time" "strconv" ) var wg sync

davidsu33的专栏 4645

如何使用goquery进行HTML解析以及它的源码分析和实现原理

goquery是一款基于Go语言的HTML解析库,它使用了类似于jQuery的语法,使得在Go语言中进行HTML解析变得更加方便。使用goquery,开发者可以在HTML文档中轻松地查询、遍历和操作文档中的各种元素和属性。在HTML文档中查找、筛选和遍历元素获取元素的属性、文本内容、HTML内容等信息对元素进行添加、修改、删除等操作在HTML文档中执行CSS选择器操作支持链式调用,可以方便地进行多个操作组合。

qq_38334677的博客 2158

Go语言爬虫:goquery 的详细使用

goquery 是 Go 语言中处理 HTML 的瑞士军刀,它将 jQuery 的语法和便利性带到了 Go 的世界里。

数据知道的博客 3952

goquery的使用

title: goquery的使用 tags: go,goquery,爬虫 author: Clown95 本文参考 飞雪无痕 的 《golang goquery selector(选择器) 示例大全》 概述 相信很多小伙伴对爬虫有着很大的兴趣,今天我们就来说下go语言的爬虫利器goquery,有使用过jquery的小伙伴是不是看着这个很眼熟?goquery类似jquery,它是jquer...

Clown95 2万+

超聚变安装银河麒麟服务器系统ky10-server-x86

超聚变-通过BMC口进服务器管理界面如下图为BMC管理口:默认BMC口IP:https://192.168.2.100l浏览器打开网页,输入用户名和密码登陆后,如下图红框处,选择“启动虚拟控制台”——选择“HTML集成远程控制台”系统银河麒麟服务器系统ky10 server x86选择镜像文件X86架构我们一般选择下图2212版本选择启动方式:光驱重启出现安装图形化界面选装安装系统的磁盘系统安装盘选完后如下图,会置灰创建root密码开始安装系统首次进入,有协议界面。

zengliguang的专栏 5966

500道C++面试高频题解析(附答案、实战示例与进阶追问)

本文提供500道C++面试高频题的详细解析,涵盖基础概念到进阶应用,包括面向对象编程、内存管理、现代C++特性、并发编程等核心考点。每道题配有实战示例和进阶追问,帮助开发者突破八股文局限,掌握解决实际问题的能力,适合准备C++技术面试的工程师系统复习。

weixin_29002595的博客 312

Go 每日一库之 goquery

简介 goquery是用 Go 语言编写的一个类似于 jQuery 的库。它基于 HTML 解析库net/html和 CSS 库cascadia,提供与 jQuery 相近的接口。Go 著名的爬虫框架colly就是基于 goquery 的。 快速使用 本文代码使用 Go Modules。 创建目录并初始化: $ mkdir goquery && cd goquery $ go mod init github.com/darjun/go-daily-lib/goquery 安装g

dz45693的专栏 2883

【LaTex】LaTex的下载与安装(2025新手小白超详细、超简洁 Windows系统)

安装地点(1)texlive的安装:首先打开下载好的安装包,找到这个文件前面缺少了一页emm我去截取其他人的作为示范然后点击安装安装时间较久,大概要一个小时左右。具体要看个人电脑性能情况。如图显示如上图,则安装成功。图中是TeXstudio 4.8.7版本针对不同操作系统和使用场景的安装包 ,区别如下:(按需求下载)

爱学习的capoo的博客 5104

go 语言爬虫库goquery介绍

爬虫,又称网页抓取、网络蜘蛛或网络爬虫,是一种自动浏览互联网并从网站上获取信息的程序或脚本。本文介绍goquery框架,并用之实现一个爬取自己主页,为自己添加流量的小爬虫。

个人博客,记录了本人学习的各种有趣的技术。 4558

开发具有情感分析能力的AI Agent

本文将深入探讨开发具有情感分析能力的AI Agent的各个方面。我们将首先介绍情感分析的基础知识,包括定义、背景和应用领域。接着,我们将详细讲解情感分析的核心概念、数据处理方法和算法原理。随后,文章将展示如何设计情感分析系统架构,并进行项目实战,包括环境安装、源代码实现和案例分析。最后,我们将总结最佳实践和注意事项,为读者提供进一步学习的资源。情感分析(Sentiment Analysis),也称为意见挖掘,是自然语言处理(NLP)的一个分支。

SuperAGI2025 1146

Vivado报错-4 [Routed 35-3424] SLL Assignment failed ILP VU19P

Vivado报错[Routed 35-3424] SLL Assignment failed ILP VU19P

weixin_39896700的博客 1409

Golang 爬虫框架 Goquery的使用

介绍 goquery brings a syntax and a set of features similar to jQuery to the Go language. It is based on Go’s net/html package and the CSS Selector library cascadia. Since the net/html parser returns nod...

LU_ZHAO的博客 2232

Dify 第 3 篇 Dify 入门示例 - 聊天助手

本文介绍了如何使用Dify平台快速搭建一个聊天助手。首先通过创建空白应用并选择"聊天助手"模板完成基础设置,然后安装配置通义千问等大语言模型(LLM)并设置API密钥。进阶部分演示了如何创建支持编程语言选择的代码解释器,包括添加提示词约束、插入变量、设置开场白等功能。最后展示了运行效果:用户可选择编程语言后输入代码,系统会给出相应解释。文章还提到应用支持发布共享,并附有Dify官方文档参考链接。

甘蓝的专栏 863

Golang爬虫(二):goquery库的使用

简介 goquery为Go语言带来了类似于jQuery的语法和一组特性。它基于Go的net / html包和CSS Selector库cascadia。由于net / html解析器返回节点,而不是功能齐全的DOM树,因此jQuery的有状态操作函数(如height(),css(),detach())已经停止。 此外,因为net / html解析器需要UTF-8编码,所以goquery也是如此:调...

qq_36314165的博客 1506

Linux(31)Rockchip RK3568 Ubuntu22.04上部署 Docker: 问题与解决方案

本博客在总结这些问题及其解决方案,为遇到类似问题的兄弟提供参考,如果我后续有碰到其他Docker 问题也会在此更新补充。

我其实什么都不会 1646

华为OD机试 - 末世分配资源包 - 二分查找 + 贪心(Python/JS/C/C++ 新系统 100分)

本专栏收录于《华为OD机试真题(Python/JS/C/C++)》。刷的越多,抽中的概率越大,私信哪吒,备注华为OD,加入华为OD刷题交流群,每一题都有详细的答题思路、详细的代码注释、3个测试用例、为什么这道题采用XX算法、XX算法的适用场景,发现新题目,随时更新。末世时代,政府为各地方配资源,现有资源分配表 nums[n],要求按如下规则分配给 k 个营地:在最优平均分配情况下,得到最大团队所获得的资源数4,3,6,9,7 216最佳划分之一:[4,3,6] -> 13 [9,7] -> 16最大

学Java,找哪吒 224

goquery的初步使用

goquery的初步使用

yuchenfw的博客 3204

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

goquery 查找html标签,goquery库的使用

简介goquery为Go语言带来了类似于jQuery的语法和一组特性。它基于Go的net / html包和CSS Selector库cascadia。由于net / html解析器返回节点,而不是功能齐全的DOM树,因此jQuery的有状态操作函数(如height(),css(),detach())已经停止。此外,因为net / html解析器需要UTF-8编码,所以goquery也是如此:调用者...

weixin_30788095的博客 1823

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

go 语言爬虫库goQuery 的详细使用(知乎日报详情页解析示例)

知乎日报这个案例很经典,有比较完整的API,很值得模仿学习。也很简单,唯一需要注意的是日报详情的设计,因为知乎日报的详情接口,竟返回的是html,这.....uniapp小程序开发 | 从零实现一款影视类app (后台接口实现,go-zero微服务的使用)_uniapp开源影视app-优快云博客GoQuery是专为Go(Golang)语言设计的一个强大的HTML解析和查询库。它模仿了jQuery的API风格,使得在Go中处理HTML文档变得简单且直观。

猫哥 的沉淀、积累、总结。天天学习,好好向上...c/c++,嵌入式 linux,Android,HarmonyOS,AIOT) 2226

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Golang学习日志 ━━ goQuery 的使用

简介 goquery为Go语言带来了类似于jQuery的语法和一组特性。它基于Go的net/html包和CSS Selector库cascadia。由于net/html解析器返回节点,而不是功能齐全的DOM树,因此jQuery的有状态操作函数(如height(),css(),detach())已经停止。 此外,因为net/html解析器需要UTF-8编码,所以goquery也是如此:调用者有责任确保源文档提供UTF-8编码的HTML。 安装 go get github.com/PuerkitoBio/goq

暂时先用这个名字 3124

goquery使用

做过 Web 开发的,应该都用过或听过 jQuery,它提供了方便的操作 DOM 的 API。使用 Go 语言做服务器端开发,有时候需要解析 HTML 文件,比如抓取网站内容、写一个爬虫等。这时候如果有一个类似 jQuery 的库可以使用,操作 DOM 会很方便,而且,上手也会很快。github.com/PuerkitoBio/goquery 这个库就实现了类似 jQuery 的功能,让你能方便的使

shapsnail的专栏 2742

【GoCN酷Go推荐】Html解析利器-goquery库

简介什么是goquery?goquery是由Go实现的基于Go的net/html包和CSS选择器库cascadia的HTML解析库。由于net/html解析器需要UTF-8编码,goque...

Go中国 961

goquery php,Go 每日一库之 goquery

简介goquery是用 Go 语言编写的一个类似于 jQuery 的库。它基于 HTML 解析库net/html和 CSS 库cascadia,提供与 jQuery 相近的接口。Go 著名的爬虫框架colly就是基于 goquery 的。快速使用本文代码使用 Go Modules。创建目录并初始化:$ mkdir goquery && cd goquery$ go mod init...

weixin_34161139的博客 300

Go语言爬虫框架之Colly和Goquery

文章目录写在前面Go语言爬虫框架之Colly和Goquery网络爬虫爬虫的简单算法Colly开始OnHTMLOnRequest / OnResponseHTMLElementBringing in Goquery写一个完整的爬虫 写在前面 此文翻译自点击阅读原文,建议英语能力好的同学阅读原文进行学习。 点击阅读Colly文档,点击阅读Goquery文档 Go语言爬虫框架之Colly和Goquery Python框架框架比较有BeautifulSoup或Scrapy,基于Go的爬虫框架是比较强健的,尤其Col

BigManing的博客 2865

【GO】21.goquery html页面分析golang库

下载包: go get github.com/PuerkitoBio/goquery 示例代码: package main import ( "fmt" "log" "net/http" "github.com/PuerkitoBio/goquery" ) func ExampleScrape() { // Request the HTML pa...

chen_peng7的博客 817
上一篇: Golang(7)-net/http包的使用
下一篇: 设计模式(1)-策略模式
BoringRong
BoringRong 领域专家: 后端开发技术领域 领域专家: 后端开发技术领域
博客等级 码龄9年 2万+粉丝 386原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BoringRong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值