In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use Python to write a map of the number of people diagnosed with new coronavirus". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use Python to write a map of the number of people diagnosed with new coronavirus.
The recent development of pneumonia is a bit frightening. Just know the pyecharts library of python, think of the visual characteristics of pyecharts, you can pick up the official website of real-time broadcast of pneumonia and make a map.
The first step is to pick up the data: a big problem was found that the number of diagnosed people in each province was not found in the source code of the web page. Baidu just knew that this is produced by js rendering, and it is another check. Find a way. Just use selenium to perform the process of web page rendering, first install selenium.
Pip install selenium
I also need webdriver to launch the browser when referencing the library. I use google, so I want to download chromedriver. Find your own version of chrome first
Then find the corresponding version of chromedriver and download
After downloading, extract the exe file to the coding folder and you can use it. Now you can climb the data and import the library.
From selenium import webdriver
Then drive the browser and access the URL
Driver = webdriver.Chrome () driver.get ('https://news.163.com/special/epidemic/#map_block')
Remember to set a wait here, otherwise the program may not be open after running the page when crawling the data.
Driver.implicitly_wait (5)
Then you can get the data.
Data = driver.page_source
You still have to filter the data you want with regular expressions, and don't forget to import import re before
Name = re.findall (r'(. *?)', data,re.S) [1:32] value = re.findall (r'span class= "item_confirm" > (. *)', data,re.S) [1:32]
Climb successfully
Now that you've crawled the data, it's time for the visualization part, using the Map block of pyecharts.
The link to the pyecharts document is here-- follow the document to import the library
The code for the map is as follows
But whether I Faker this or not, I checked later and used this boss's method: the address.
The overall code is as follows:
From pyecharts.charts import Mapfrom pyecharts import options as optsimport refrom selenium import webdriverdriver = webdriver.Chrome () driver.get ('https://news.163.com/special/epidemic/#map_block')driver.implicitly_wait(5)#data = driver.find_element_by_xpath (' / html/body/p [3] / p [2] / p [2] / ul [1] / li [1] / p/span [1]') .text # .get_attribute ('href') data = Driver.page_sourceattr = re.findall (r'(. *?)' Data,re.S) [1:32] value = re.findall (r'span class= "item_confirm" > (. *?)', data,re.S) [1:32] sequence = list (zip (attr, value)) def map_visualmap (sequence, year)-> Map: C = (Map () .add (year, sequence, "china",) .set _ global_opts (title_opts=opts.TitleOpts (title= "number of new coronavirus confirmed in provinces"), visualmap_opts=opts.VisualMapOpts (max_=130) Min_=95),) return cmap = map_visualmap (sequence, 'novel coronavirus infection') map.render (path='2020.html')
Take a look at the results!
At this point, I believe you have a deeper understanding of "how to use Python to write a map of the number of people diagnosed with new coronavirus". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.