python 仪表盘

Dashboard scraping is a useful skill to have when the only way to interact with the data you need is through a dashboard. We’re going to learn how to scrape data from a dashboard using the Selenium and Beautiful Soup packages in Python. The Selenium package allows you to write Python code to automate web browser interaction, and the Beautiful Soup package allows you to easily pull data from the HTML code that produces the webpage you want to scrape.

当与所需数据进行交互的唯一方法是通过仪表板时,仪表板抓取是一项有用的技能。 我们将学习如何使用Python中的Selenium和Beautiful Soup软件包从仪表板上抓取数据。 Selenium程序包允许您编写Python代码来自动执行Web浏览器交互,而Beautiful Soup程序包则使您可以轻松地从生成您要抓取的网页HTML代码中提取数据。

Our goal is to scrape the Fort Bend County Community Impact Dashboard that visualizes the COVID-19 situation in Fort Bend County in Texas. We will extract the history of total tests performed and the daily case counts reported so that we can estimate the percent of positive cases in Fort Bend County.

我们的目标是刮擦本德堡县社区影响仪表板 ,以可视化方式显示德克萨斯州本德堡县的COVID-19情况。 我们将提取进行的总检测的历史记录和每日报告的病例计数,以便我们可以估算本德堡县阳性病例的百分比。

Note that all of the code in this tutorial is written in Python version 3.6.2.

请注意,本教程中的所有代码都是使用Python 3.6.2版编写的。

步骤1:导入Python软件包,模块和方法 (Step 1: Import Python Packages, Modules, and Methods)

The first step is to import the Python packages, modules, and methods needed for dashboard scraping. The versions of the packages used in this tutorial are listed below.

第一步是导入仪表板抓取所需的Python包,模块和方法。 下面列出了本教程中使用的软件包的版本。

步骤2:抓取HTML源代码 (Step 2: Scrape HTML Source Code)

The next step is to write Python code to automate our interaction with the dashboard. Before writing any code, we must look at the dashboard and inspect its source code to identify the HTML elements that contain the data we need. The dashboard source code refers to the HTML code that tells your browser how to render the dashboard web page. To view the dashboard source code, navigate to the dashboard and use the keyboard shortcut Ctrl+Shift+I. An interactive panel containing the dashboard source code will appear.

下一步是编写Python代码来自动化我们与仪表板的交互。 在编写任何代码之前,我们必须查看仪表板并检查其源代码以识别包含我们所需数据HTML元素。 仪表板源代码是指HTML代码,它告诉您的浏览器如何呈现仪表板网页。 要查看仪表板源代码,请导航至仪表板并使用键盘快捷键Ctrl+Shift+I 将出现一个包含仪表板源代码的交互式面板。

Notice that the history of total tests performed and the daily case counts reported are only visible after clicking the “History” tab in the “Total Numbers of Tests Performed at County Sites” panel and the “Daily Case Count” tab in the “Confirmed Cases” panel, respectively. This means that we need to write Python code that automatically clicks on the “History” and “Daily Case Count” tabs so that the history of total tests performed and the daily case counts reported will be visible to Beautiful Soup.

请注意,仅在单击“县站点执行的测试总数”面板中的“历史记录”选项卡和“已确认案例”中的“每日案例计数”选项卡之后,才可以执行总测试的历史记录和报告的每日案例计数”面板。 这意味着我们需要编写Python代码,该代码自动单击“历史记录”和“每日案例计数”选项卡,以便Beautiful Soup可以看到执行的总测试的历史记录和每日报告的案例计数。

Fort Bend County Community Impact Dashboard on July 10th, 2020本德堡县社区影响仪表板

To find the HTML element that contains the “History” tab, use the shortcut Ctrl+Shift+C and then click on the "History" tab. You will see in the source code panel that the "History" tab is in a div element with ID "ember208".

要查找包含“历史记录”选项卡HTML元素,请使用快捷键Ctrl+Shift+C ,然后单击“历史记录”选项卡。 您将在源代码面板中看到“历史记录”选项卡位于ID为“ ember208”的div元素中。

History Tab Source Code
历史记录选项卡源代码

Following the same steps for the “Daily Case Count” tab, you will see that the “Daily Case Count” tab is in a div element with ID “ember238”.

按照“每日案件计数”标签的相同步骤,您将看到“每日案件计数”标签位于ID为“ ember238”的div元素中。

Source Code of Daily Case Count Tab
每日病例计数选项卡的源代码

Now that we have identified the elements we need, we can write code that:

现在我们已经确定了所需的元素,我们可以编写代码:

  1. Launches the dashboard in Chrome在Chrome中启动仪表板
  2. Clicks on the “History” tab once the “History” tab finishes loading一旦“历史记录”选项卡完成加载,请单击“历史记录”选项卡
  3. Clicks on the “Daily Case Count” tab once the “Daily Case Count” tab finishes loading一旦“每日病例数”选项卡完成加载,请单击“每日病例数”选项卡
  4. Extracts the dashboard HTML source code提取仪表板HTML源代码
  5. Exits Chrome退出Chrome

步骤3:从HTML解析数据 (Step 3: Parse Data from HTML)

Now, we need to parse the HTML source code to extract the history of total tests performed and the daily case counts reported. We will begin by looking at the dashboard source code to identify the HTML elements that contain the data.

现在,我们需要解析HTML源代码,以提取执行的总测试的历史记录和每日报告的病例数。 我们将从查看仪表板源代码开始,以识别包含数据HTML元素。

To find the div element that contains the history of total tests performed, use the Ctrl+Shift+C shortcut and then click in the general area of the "Testing Sites" plot. You will see in the source code that the entire plot is in the div element with ID "ember96".

要查找包含已执行的全部测试的历史记录的div元素,请使用Ctrl+Shift+C快捷键,然后单击“测试站点”图的常规区域。 您会在源代码中看到整个图位于ID为“ ember96”的div元素中。

Source Code of Testing Sites Plot
测试站点图的源代码

If you hover over a specific data point, a label containing the date and number of tests performed will appear. Use the Ctrl+Shift+C shortcut and click on a specific data point. You will see that the label text is stored as the aria-label attribute of a g element.

如果将鼠标悬停在特定数据点上,则会显示一个标签,其中包含执行的测试的日期和数量。 使用Ctrl+Shift+C快捷键,然后单击特定的数据点。 您将看到标签文本存储为g元素的aria-label属性。

Source Code of Testing Sites Data Labels
测试站点数据标签的源代码

Following the same steps for the daily case counts reported, you will see that the plot of daily case counts is in the div element with ID “ember143”.

按照报告的每日案件计数的相同步骤,您将看到每日案件计数的图位于ID为“ ember143”的div元素中。

Source Code of Daily Cases based on Report Date Plot
基于报告日期图的日常案例源代码

If you hover over a specific data point, a label containing the date and the number of positive cases reported will appear. Using the Ctrl+Shift+C shortcut, you will notice that the data are also stored in the aria-label attribute of g elements.

如果将鼠标悬停在特定数据点上,将显示一个标签,其中包含日期和报告的阳性病例数。 使用Ctrl+Shift+C快捷键,您会注意到数据也存储在g元素的aria-label属性中。

Source Code of Daily Cases based on Report Date Data Labels
基于报告日期数据标签的日常案例的源代码

Once we have the elements that contain the data, we can write code that:

一旦有了包含数据的元素,就可以编写代码:

  1. Finds the div element that contains the plot of the total tests performed and pulls the total tests performed data查找包含执行的总测试次数的图的div元素,并提取执行的总测试数据
  2. Finds the div element that contains the plot of the daily case counts and pulls the daily case count data查找包含每日案件计数图的div元素,并提取每日案件计数数据
  3. Combines the data in a pandas dataframe and exports it to a CSV将数据合并到pandas数据框中,并将其导出到CSV

步骤4:计算正率 (Step 4: Calculate Positivity Rate)

Now, we can finally estimate the COVID-19 positivity rate in Fort Bend County. We will divide the cases reported by the tests performed and calculate the 7-day moving averages. It is unclear from the dashboard whether the reported positive cases include cases that were determined through tests not conducted by the county (e.g. tests conducted at a hospital or clinic). It is also unclear when the tests for the positive cases were conducted since the dashboard only displays the reported case date. That is why the positivity rates derived from these data are only considered a rough estimate for the true positivity rate.

现在,我们终于可以估算出本德堡县的COVID-19阳性率。 我们将通过执行的测试报告的案例相除,并计算7天移动平均值。 从仪表板尚不清楚,报告的阳性病例是否包括那些不是由县进行的检测(例如,在医院或诊所进行的检测)确定的病例。 还不清楚何时进行阳性病例的测试,因为仪表板仅显示报告的病例日期。 这就是为什么仅将这些数据得出的阳性率视为真实阳性率的粗略估计。

翻译自: https://towardsdatascience.com/how-to-scrape-a-dashboard-with-python-8b088f6cecf3

python 仪表盘


http://www.taodudu.cc/news/show-994896.html

相关文章:

  • aws emr 大数据分析_DataOps —使用AWS Lambda和Amazon EMR的全自动,低成本数据管道
  • 先进的NumPy数据科学
  • 统计和冰淇淋
  • 对数据仓库进行数据建模_确定是否可以对您的数据进行建模
  • python内置函数多少个_每个数据科学家都应该知道的10个Python内置函数
  • 针对数据科学家和数据工程师的4条SQL技巧
  • 芒果云接吗_芒果糯米饭是生产力的关键吗?
  • 公司生日会生日礼物_你的生日有多受欢迎?
  • 旧金山字体_旧金山建筑业的兴衰。 施工趋势与历史
  • lambda函数,函数符_为什么您永远不应该在Lambda函数中使用print()
  • ai 中 统计_AI统计(第2部分)
  • twitter数据分析_Twitter上最受欢迎的数据科学文章主题
  • 是什么使波西米亚狂想曲成为杰作-数据科学视角
  • 流行编程语言_编程语言的流行度排名
  • corba的兴衰_数据科学薪酬的兴衰
  • 通才与专家_那么您准备聘请数据科学家了吗? 通才还是专家?
  • 数据科学家 数据工程师_数据科学家实际上赚了多少钱?
  • spotify歌曲下载_使用Spotify数据预测哪些“ Novidades da semana”歌曲会成为热门歌曲
  • 功能测试代码python_如何使您的Python代码更具功能性
  • 普通话测试系统_普通话
  • 动漫数据推荐系统
  • Alex Hanna博士:Google道德AI小组研究员
  • python度量学习_Python的差异度量
  • 网页视频15分钟自动暂停_在15分钟内学习网页爬取
  • django 性能优化_优化Django管理员
  • ai驱动数据安全治理_JupyterLab中的AI驱动的代码完成
  • python中定义数据结构_Python中的数据结构—简介
  • 数据质量提升_合作提高数据质量
  • 删除wallet里面登机牌_登机牌丢失问题
  • 字符串操作截取后面的字符串_对字符串的5个必知的熊猫操作

python 仪表盘_如何使用Python刮除仪表板相关推荐

  1. 2018年python薪资_最好的Python:2017和2018年至今我最喜欢的文章集

    2018年python薪资 我打算发布此收藏集 (My intention with publishing this collection) Last year I only used Medium ...

  2. python股市_如何使用python和破折号创建仪表板来主导股市

    python股市 始终关注大局 (Keep Your Eyes on the Big Picture) I've been fascinated with the stock market since ...

  3. python 切片_全面解读Python高级特性切片

    大家好,欢迎来到Crossin的编程教室! 众所周知,我们可以通过索引值(或称下标)来查找序列类型(如字符串.列表.元组-)中的单个元素,那么,如果要获取一个索引区间的元素该怎么办呢? 切片(slic ...

  4. 学习python课程_想学习Python吗? 这是我们的免费4小时互动课程

    学习python课程 Python is a popular, versatile and easy-to-learn language. It's the go-to language for AI ...

  5. 有趣的超短python代码_有趣的python精短程序

    python可以简单优美,也很有趣,下面是收集的例子: 1.一句话开始一个http的文件服务器: $ python -m SimpleHTTPServer Serving HTTP on 0.0.0. ...

  6. 少儿编程python教材_少儿编程|Python环境安装

    一.为什么要学Python? 小学 山东,浙江,北京地区小学已将Python内容纳入教材 高中 浙江省已将信息技术教材编程语言替换为Python 大学 计算机二级考试加入"Python 语言 ...

  7. 微软发布的python教程_微软发布Python 教程《Develop with Python on Windows》

    微软近日上线了一套 Python 教程<Develop with Python on Windows>,文档内容包括设置 Python 开发环境.在 Windows 与 WSL 子系统中安 ...

  8. python竞赛_浅谈Python在信息学竞赛中的运用及Python的基本用法

    浅谈Python在信息学竞赛中的运用及Python的基本用法 前言 众所周知,Python是一种非常实用的语言.但是由于其运算时的低效和解释型编译,在信息学竞赛中并不用于完成算法程序.但正如LRJ在& ...

  9. python程序_正确配置Python应用程序

    让我们来讨论一下如何配置Python应用程序,特别是那些可能存在于多个环境中的应用程序--开发环境.模拟环境.生产环境等等-- 应用程序中使用的工具和框架并不是特别重要,因为我将在下面概述的方法是基于 ...

最新文章

  1. 使用 Inception-v3,实现图像识别(Python、C++)
  2. getopt( )和 getopt_long( )
  3. CAP理论与分布式事务解决方案
  4. d.ts文件可以注释html吗,如何编写一个d.ts文件的步骤详解_旧店_前端开发者
  5. php 几秒后返回,php计算两个时间差并返回差多少天、时、分、秒
  6. UITextView详解
  7. wince系统_汽车操作系统分类
  8. 使用Xamarin在Visual Studio中开发Android应用
  9. SPSS学习笔记(三)方差分析ANOVA(F检验)
  10. 微软私有云系列 ----SQL 云部署
  11. 2:STM32CubeMX配置STM32F103C8T6驱动-SPI驱动
  12. 单商户商城系统功能拆解40—分销应用—分销设置
  13. VS编译失败,找不到源文件!!!
  14. python嵌入式开发实战_python在嵌入式
  15. c++类的类型转换函数
  16. html控制checkbox选中状态,怎么设置checkbox 选中状态
  17. python 词语频率统计_计算词和词组频率的Python nltk
  18. SpringBoot集成mysql-connector-java数据库驱动
  19. 创建react项目 Linux,idea2018 快速搭建react项目指南
  20. 01-21 IO流(字符流与字节流)

热门文章

  1. c++中的map容器
  2. Ubuntu停止维护版本的软件源配置和系统升级方法
  3. 【Linux】Ubuntu 18下安装Vim自动补全插件YouCompleteMe(可高速下载安装)
  4. Linux之GDB调试命令
  5. ptmalloc堆内存管理机制(主要讨论Linux x86下32位系统)
  6. 《Python》进程收尾线程初识
  7. DataGridView控件用法二:常用属性
  8. 在双系统(Windows与Ubuntu)下删除Ubuntu启动项
  9. Lua初学习 9-12 基础
  10. DB天气app冲刺二阶段第七天