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 1
1
"""
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
3
3
* The main motivation to use lxml in place of bs4 is that it is faster and therefore
4
4
more convenient to use in Python web projects (e.g. Django or Flask-based)
5
5
"""
9
9
# dependencies = [
10
10
# "httpx",
11
11
# "lxml",
12
- # "requests_html",
13
12
# ]
14
13
# ///
15
14
16
15
from typing import NamedTuple
17
16
18
17
import httpx
19
18
from lxml import html
20
- from requests_html import HTMLSession
21
19
22
20
23
21
class CovidData (NamedTuple ):
24
- cases : int
25
- deaths : int
26
- recovered : int
22
+ cases : str
23
+ deaths : str
24
+ recovered : str
27
25
28
26
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 :
30
28
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 )
36
29
return CovidData (
37
30
* html .fromstring (httpx .get (url , timeout = 10 ).content ).xpath (xpath_str )
38
31
)
You can’t perform that action at this time.
0 commit comments