Skip to content

Commit 62d9f9a

Browse files
Update covid_stats_via_xpath.py
1 parent 4c3a58c commit 62d9f9a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

web_programming/covid_stats_via_xpath.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
# dependencies = [
1010
# "httpx",
1111
# "lxml",
12+
# "requests_html",
1213
# ]
1314
# ///
1415

1516
from typing import NamedTuple
1617

1718
import httpx
1819
from lxml import html
20+
from requests_html import HTMLSession
1921

2022

2123
class CovidData(NamedTuple):
@@ -26,11 +28,17 @@ class CovidData(NamedTuple):
2628

2729
def covid_stats(url: str = "https://www.worldometers.info/coronavirus/") -> CovidData:
2830
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)
2936
return CovidData(
3037
*html.fromstring(httpx.get(url, timeout=10).content).xpath(xpath_str)
3138
)
3239

3340

41+
3442
fmt = """Total COVID-19 cases in the world: {}
3543
Total deaths due to COVID-19 in the world: {}
3644
Total COVID-19 patients recovered in the world: {}"""

0 commit comments

Comments
 (0)