File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change 9
9
# dependencies = [
10
10
# "httpx",
11
11
# "lxml",
12
+ # "requests_html",
12
13
# ]
13
14
# ///
14
15
15
16
from typing import NamedTuple
16
17
17
18
import httpx
18
19
from lxml import html
20
+ from requests_html import HTMLSession
19
21
20
22
21
23
class CovidData (NamedTuple ):
@@ -26,11 +28,17 @@ class CovidData(NamedTuple):
26
28
27
29
def covid_stats (url : str = "https://www.worldometers.info/coronavirus/" ) -> CovidData :
28
30
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 )
29
36
return CovidData (
30
37
* html .fromstring (httpx .get (url , timeout = 10 ).content ).xpath (xpath_str )
31
38
)
32
39
33
40
41
+
34
42
fmt = """Total COVID-19 cases in the world: {}
35
43
Total deaths due to COVID-19 in the world: {}
36
44
Total COVID-19 patients recovered in the world: {}"""
You can’t perform that action at this time.
0 commit comments