File tree Expand file tree Collapse file tree 1 file changed +5
-12
lines changed
Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Original file line number Diff line number Diff line change 11"""
2- This is to show simple COVID19 info fetching from worldometers site using lxml
2+ This is to show simple COVID19 info fetching from worldometers archive site using lxml
33* The main motivation to use lxml in place of bs4 is that it is faster and therefore
44more convenient to use in Python web projects (e.g. Django or Flask-based)
55"""
99# dependencies = [
1010# "httpx",
1111# "lxml",
12- # "requests_html",
1312# ]
1413# ///
1514
1615from typing import NamedTuple
1716
1817import httpx
1918from lxml import html
20- from requests_html import HTMLSession
2119
2220
2321class CovidData (NamedTuple ):
24- cases : int
25- deaths : int
26- recovered : int
22+ cases : str
23+ deaths : str
24+ recovered : str
2725
2826
29- def covid_stats (url : str = "https://www.worldometers.info/coronavirus/" ) -> CovidData :
27+ def covid_stats (url : str = "https://web.archive.org/web/20250825095350/https:// www.worldometers.info/coronavirus/" ) -> CovidData :
3028 xpath_str = '//div[@class = "maincounter-number"]/span/text()'
31- session = HTMLSession ()
32- r = session .get (url )
33- print (r .html .html )
34- r .html .render ()
35- print (r .html .html )
3629 return CovidData (
3730 * html .fromstring (httpx .get (url , timeout = 10 ).content ).xpath (xpath_str )
3831 )
You can’t perform that action at this time.
0 commit comments