Run code as script and not in interactive interpreter as you do now which has
So in IDLE you do
Then
>>>
.So in IDLE you do
File ➡ New File
in this window paste in all of code and save as eg scrape.py
.Then
Run ➡ Run Module(F5)
so same as step this image.