title: NameError: name 'htmltext' is not defined
body: <p>I obtain an error when i run this script:</p>
  <pre><code>import urllib.request
  import urllib.parse
  from bs4 import BeautifulSoup
  
  url = &quot;http://nytimes.com,http://nytimes.com&quot;
  
  urls = [url] #stack of urls to scrape
  visited = [url] #historic record of urls
  
  while len(urls) &gt;0:
  try:
      htmltext = urllib.request.urlopen(urls[0]).read()
  except:
      print(htmltext)
  </code></pre>
  <p>Original scipt:</p>
  <pre><code>import urllib.request
  import urllib.parse
  from bs4 import BeautifulSoup
  
  url = &quot;http://nytimes.com,http://nytimes.com&quot;
  
  urls = [url] #stack of urls to scrape
  visited = [url] #historic record of urls
  
  while len(urls) &gt;0:
  try:
      htmltext = urllib.request.urlopen(urls[0]).read()
  except:
      print(urls[0])
  soup = BeautifulSoup(htmltext)
  
  urls.pop(0)
  
  print (soup.findAll('a',href=True))
  </code></pre>
  <p>Errors:</p>
  <blockquote>
  <p>socket.gaierror: [Errno -2] Name or service not known</p>
  <p>urllib.error.URLError: urlopen error [Errno -2] Name or service not known</p>
  <p>Traceback (most recent call last):</p>
  <p>NameError: name 'htmltext' is not defined</p>
  </blockquote>