NameError in Python 3.4.3
Question: When I'm trying this with the following configuration :

  * VirtualEnv with python3.4.3
  * Running on an online IDE

When I'm trying this :

    
    
    from urllib.request import urlopen
    from urllib.error import HTTPError
    from bs4 import BeautifulSoup
    try:
        html = urlopen("http://www.pythonscraping.com/pages/pages1.html")
    
    if html is None:
            print("url not found")
    else:
        except HTTPError as e:
            print("test")
        else:
            bsObj = BeautifulSoup(html.read())
            print(bsObj)
    

I got the following error :

    
    
    ~/workspace/scrapingEnv $ python test2.py
      File "test2.py", line 7
        if html is None:
         ^
    SyntaxError: invalid syntax
    

What am I doing wrong ?


Answer: Thanks for the hints, I found a way to get around my problem :

    
    
    from urllib.request import urlopen
    from urllib.error import HTTPError
    from urllib.error import URLError
    from bs4 import BeautifulSoup
    
    try:
        html = urlopen("http://www.pythonscrapng.com/pages/pages1.html")
        bsObj = BeautifulSoup(html.read())
        print(bsObj)
    
    except HTTPError as e:
        print("test")
    except URLError as j:
        print ("No URL")
    else:
        bsObj = BeautifulSoup(html.read())
        print(bsObj)
    

