基金分析系统(三):爬取基金收益榜单

1.流程介绍

2.页面分析

3. 爬虫脚本

3.1 编写结构体

代码文件位置:service/crawl/fund/top_crawl.go

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
// 对应每一行的基金信息
type fundItem struct {
	FundCode         string `selector:"td:nth-of-type(1)"`
	FundName         string `selector:"td:nth-of-type(2)"`
	NetWorth         string `selector:"td:nth-of-type(3) > span.fb"`
	TopDate          string `selector:"td:nth-of-type(3) > span.date"`
	DayChange        string `selector:"td:nth-of-type(4)"`
	WeekChange       string `selector:"td:nth-of-type(5)"`
	MouthChange      string `selector:"td:nth-of-type(6)"`
	ThreeMouthChange string `selector:"td:nth-of-type(7)"`
	SixMouthChange   string `selector:"td:nth-of-type(8)"`
	YearChange       string `selector:"td:nth-of-type(9)"`
	TwoYearChange    string `selector:"td:nth-of-type(10)"`
	ThreeYearChange  string `selector:"td:nth-of-type(11)"`
	CurrentChange    string `selector:"td:nth-of-type(12)"`
	CreateChange     string `selector:"td:nth-of-type(13)"`
}
type TopCrawlService struct {
	Item []*fundItem `selector:"tr"`
}

td:nth-of-type(n)代表每行的第n列,@注意:这里的NetWorth和TopDate,取的都是第3列的数据

基金分析系统(一):项目介绍

1. 项目介绍

使用Go开发《基金数据分析系统》,项目系统框架是基于gin-api-template的基础上做二次开发,该系统计划完成功能,主要有: 基金数据(概括、持仓、历史业绩、财务报表)爬取、基金相似度对比、用户管理等功能。

RPC编程(二):快速入门使用

1. 介绍

Go语言标准包(net/rpc)已经提供了对RPC的支持,而且支持三个级别的RPC:TCP、HTTP和JSONRPC。但Go语言的RPC包是独一无二的RPC,它和传统的RPC系统不同,它只支持Go语言开发的服务器与客户端之间的交互,因为在内部,它们采用了Gob来编码。

RPC编程(一):初步了解RPC

1. 什么是RPC

RPC(Remote Procedure Call,远程过程调用)是一种进程间的通信方式,它是一种技术思想(概念),而不是规范,它允许程序调用另一个地址空间(通常是共享网络的另一台机器)的过程函数,而开发者无需额外地为这个调用过程编写网络通信相关代码细节。

框架开发(三):框架开发-集成Redis

1.客户端介绍

redis官网推荐使用redigo(https://github.com/gomodule/redigo),截止到今天Github Start是8.2k 但go-redis(https://github.com/go-redis/redis)使用的人更多, 并且go-redis封装得更好。截止到今天Github Start 是10.8k。

框架开发(二):框架开发-集成Gorm

1.安装

1
2
go get -u gorm.io/gorm
go get -u gorm.io/driver/mysql

2.配置相关

2.1 编写配置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[mysql]
host=127.0.01
port=3306
database=test
userName=root
password=root
charset=utf8mb4
# 表前缀
table_pre=app_
# 设置闲置的连接数,默认值为2;
max_idle_conn=10
# 设置最大打开的连接数,默认值为0,表示不限制。
max_open_conn=100
# 设置了连接可复用的最大时间。
max_life_time=1h
# 支持把数据库datetime和date类型转换为golang的time.Time类型
parse_time=true
# 使用系统本地时区
loc=Local
# 连接超时时间
timeout=10s
# 慢sql时间,单位毫秒
slow_sql_time=50ms
# 是否打印SQL
print_sql_log=true

2.2 定义Mysql配置结构体

文件: app/config/mysql_config.go