File tree 1 file changed +6
-1
lines changed
src/04-asyncio/web_scraping/async_scrape
1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 4
4
import bs4
5
5
from colorama import Fore
6
6
7
+ # Older versions of python require calling loop.create_task() rather than on asyncio.
8
+ # Make this available more easily.
9
+ global loop
10
+
7
11
8
12
async def get_html (episode_number : int ) -> str :
9
13
print (Fore .YELLOW + f"Getting HTML for episode { episode_number } " , flush = True )
@@ -28,6 +32,7 @@ def get_title(html: str, episode_number: int) -> str:
28
32
29
33
30
34
def main ():
35
+ global loop
31
36
loop = asyncio .get_event_loop ()
32
37
loop .run_until_complete (get_title_range ())
33
38
print ("Done." )
@@ -46,7 +51,7 @@ async def get_title_range():
46
51
47
52
tasks = []
48
53
for n in range (150 , 160 ):
49
- tasks .append ((n , asyncio .create_task (get_html (n ))))
54
+ tasks .append ((n , loop .create_task (get_html (n ))))
50
55
51
56
for n , t in tasks :
52
57
html = await t
You can’t perform that action at this time.
0 commit comments