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
Applicable source code
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
#-*-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.
Answer # 1
You must import the time module.
import time import requests from requests.compat import urljoin from bs4 import BeautifulSoup
- python scraping: how to use pickle
- python 3x - external program execution fails
- i don't know how to specify selector in scraping in python
- python - i think the scraping print(datatext) part is correct, but somehow an error occurs
- [python] tag acquisition for image scraping
- python - scraping multiple urls in a loop
- python - i cannot use timesleep() in tkinter of pytnon
- i want to narrow down the scraping target using enumerate in python
- python scraping chromedriver doesn't work in headless mode
- web scraping in python:error in send_keys
- web scraping doesn't work with python3
- python - deploy to heroku fails with docker + django configuration
- python - i want to get a specific element by scraping
- scraping in python:'nonetype' object has no attribute'gettext'
- python - is it ideal that cms and scraping language should be unified?
- python - i want to retrieve the contents of the href tag from the html of the specified url (scraping)
- python 3x - scraping only elements within tabs
- python - please tell me about scraping
- python 3x - specify scraping destination with pyquery
- python - i want to be able to get the text inside a child element by scraping
- python - how to process scraped data
- about scraping in python
- python - i want to let selenium click the pull-down menu of vue's combobox
- create an array from python csv
- python csv writing
- python - i want to scrape information in detail
- tell me about python iteration statements
- python - html file scraping (character code related errors)
- python - i want to automatically log in to soundcloud
- python - goo japanese dictionary scraping