Home>

I'm new to Python. As the title suggests, trying to execute time.sleep (1) will result in an error.
The source code is as follows. If i have any problems other than the applicable parts, please let me know.

The local file name has the real name part set to 0000.

Error message
NameError Traceback (most recent call last)
<ipython-input-4-68e4b63342f5>in<module>()
      8 soup = BeautifulSoup (requests.get (URL) .content, 'html.parser')
      9
--->10 time.sleep (1)
     11
     12 for link in soup.find_all ("img", limit = 10):
NameError: name 'time' is not defined
Applicable source code
#-*-coding: utf-8-*-
import requests
from requests.compat import urljoin
from bs4 import BeautifulSoup
URL = 'https://store.nike.com/us/en_us/pw/mens-running-shoes/7puZ8yzZoi3?ipp=63'
images = []
soup = BeautifulSoup (requests.get (URL) .content, 'html.parser')
time.sleep (1)
for link in soup.find_all ("img", limit = 10):
        print (link.get ("src"))
        # Convert relative URL to absolute URL
        images.append (urljoin (URL, link.get ("src")))
for target in images:
    re = requests.get (target)
    with open (r'C: \ Users \ 0000 \ Pictures' + target.split ('/') [-1], 'wb') as f:
        f.write (re.content)
print ('Completed')

I'm in trouble because an error code appears every time I touch a potentially problematic part.
I would appreciate it if you could tell me how to deal with it. Thank you.