当前位置: 首页 > news >正文

怎么给网站做apiseo基础入门免费教程

怎么给网站做api,seo基础入门免费教程,软考高级,网站制作赚钱吗爬取基金收盘价并用pyecharts进行展现 一、用到的第三方包 因为使用到了一些第三方的包,包还是比较大的如果直接从社区下载比较费劲,所以建议配置国内镜像源,这里以清华的镜像源为例。 pip config set global.index-url https://pypi.tuna…

爬取基金收盘价并用pyecharts进行展现

一、用到的第三方包

因为使用到了一些第三方的包,包还是比较大的如果直接从社区下载比较费劲,所以建议配置国内镜像源,这里以清华的镜像源为例。

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set global.trusted_host pypi.tuna.tsinghua.edu.cn

安装第三方包

pip install pandas bs4 pyecharts

二、数据获取

从网页爬取数据

import requests
from bs4 import BeautifulSoup
# 从url获取信息
response = requests.get('url地址')
# 解析HTML内容
soup = BeautifulSoup(response.text, 'html.parser')
soup.get_text()

1、从网页爬取每日最新数据

2、将数据追加存储到excel

# !/usr/bin/python
# -*-coding:utf-8 -*-
"""File        : spider.pyTime        : 2024/1/17 10:00Author      : 天选之子Email       : version     : python 3.10.11Description : 
"""
import datetime
import osimport numpy
import requests
from bs4 import BeautifulSoup
import pandasurl = "https://qt.gtimg.cn"
fund_code_list = ['sh510300', 'sz159995']
target_path = r'excel存储位置'
sheet_name = '存储的excel的sheet页'def get_fund_close_price(url_str):"""获取基金收盘价"""response = requests.get(url_str)soup = BeautifulSoup(response.text, 'html.parser')if soup is None:return '没找到'else:market = soup.get_text()return market.split('~')[4]def df_combiner(targetpath, dataframe, sheetname):"""将来源excel合并到目标excel:param targetpath::param dataframe::param sheetname::return: dataframe合并后的最终excel对象"""if not os.path.exists(targetpath):return Nonetar_data_frame = pandas.DataFrame(pandas.read_excel(targetpath, sheet_name=sheetname, keep_default_na=False))tar_date = set(numpy.array(tar_data_frame['日期']).tolist())to_date = set(numpy.array(dataframe['日期']).tolist())if to_date.issubset(tar_date):tar_df_all = tar_data_frameelse:if tar_data_frame is None:return dataframetar_df_all = pandas.concat([tar_data_frame, dataframe], ignore_index=True)return tar_df_alldef main():df_all = Nonefor fund_code in fund_code_list:fund_url = f'{url}/?q={fund_code}'result = get_fund_close_price(fund_url)print("该只基金的收盘价为:", result)print(datetime.datetime.now().strftime('%Y-%m-%d'))# 创建一个DataFramedata = {'日期': [datetime.datetime.now().strftime('%Y%m%d')], '基金代码': [fund_code], '收盘价': [result]}df = pandas.DataFrame(data)df_all = pandas.concat([df_all, df], ignore_index=True)target_df = df_combiner(target_path, df_all, sheet_name)excel_writer = pandas.ExcelWriter(target_path)target_df.to_excel(excel_writer, index=False, sheet_name='基金收盘价')excel_writer.close()if __name__ == '__main__':main()

三、展示

将获取的excel数据展示成折线图,这里使用的是pyecharts,不多废话直接上代码

# https://pyecharts.org/#/zh-cn/quickstart
import numpy
import pandas
from pyecharts import options as opts
from pyecharts.charts import Linetarget_path = r'excel位置'
sheet_name = '基金收盘价'
fund_code_list = ['sh510300', 'sz159995']
tar_data_frame = pandas.DataFrame(pandas.read_excel(target_path, sheet_name=sheet_name, keep_default_na=False))
data_date = list(set(numpy.array(tar_data_frame['日期']).tolist()))
sh510300_date = numpy.array(tar_data_frame.loc[tar_data_frame['基金代码'] == 'sh510300']['收盘价']).tolist()
sz159995_date = numpy.array(tar_data_frame.loc[tar_data_frame['基金代码'] == 'sz159995']['收盘价']).tolist()# 创建柱状图
bar_chart = Line()
bar_chart.add_xaxis(data_date)
title_opts = opts.TitleOpts(title="月度销售额折线图"),
bar_chart.add_yaxis(series_name='sh510300', linestyle_opts=opts.LineStyleOpts(color="red", width=2, is_show=True), itemstyle_opts=opts.ItemStyleOpts(color="red", border_width=1), is_smooth=True, y_axis=sh510300_date)
bar_chart.add_yaxis(series_name='sz159995_date', linestyle_opts=opts.LineStyleOpts(color="yellow", width=2, is_show=True), itemstyle_opts=opts.ItemStyleOpts(color="yellow", border_width=1), is_smooth=True, y_axis=sz159995_date)
bar_chart.set_global_opts(title_opts=opts.TitleOpts(title="基金收盘价格走势", is_show=True, pos_left='center'), xaxis_opts=opts.AxisOpts(name="月份"), yaxis_opts=opts.AxisOpts(name="收盘价(元)", min_=0, max_=10), legend_opts=opts.LegendOpts(pos_left='right'))# 渲染图表到 HTML 文件
bar_chart.render("基金收盘价.html")

展示结果如下:
在这里插入图片描述

http://www.jinmujx.cn/news/77905.html

相关文章:

  • 泉州市网站建设新闻类软文营销案例
  • 做网站编码西安网络seo公司
  • 韩国网站模板下载地址软文代写费用
  • 甘肃网站建设项目百度app在哪里找
  • 四川住房建设部网站浏览器老是出现站长工具
  • 中国建设银行积分换购网站google 推广优化
  • win7环境wordpressseo软件哪个好
  • 长沙做网站最好的公司外贸营销平台
  • 建站兔软件常见问题国际新闻最新消息中国
  • 政务网站建设目的_意义cpc广告接单平台
  • 做谷歌网站响应式模版移动优化
  • wordpress隐藏登陆界面小红书怎么做关键词排名优化
  • 做网站不备案用香港空间可以吗今日头条新闻在线看
  • bootstrap 新闻网站模板推广网站seo
  • 网站建设网页设计培训班公司网站制作公司
  • 如何优化网站目录结构一份完整的电商运营方案
  • 一个新的网站怎么做优化济南网站seo公司
  • 互联网企业推广seo报告
  • 网站策划方法企业管理咨询培训
  • 藤虎广州网站建设seo搜索引擎优化主要做什么
  • 东莞市火速网络科技有限公司seo关键词优化推广价格
  • seo网站建设哪家专业网络营销做得比较成功的企业
  • 专门做设计文案的网站自助建站系统下载
  • 备案网站可以做卡盟么网络推广合作资源平台
  • 网站建设及解析流程站长工具网站测速
  • 衢州网站建设在线之家
  • 网站建设说明书百度seo公司报价
  • 南京市城市建设档案馆网站东莞谷歌推广公司
  • 在iis上部署的网站本机无法浏览解决方法关键词林俊杰mp3在线听
  • 制作网页时一般不选用的图像文件格式是seo智能优化公司