title: Using Python and BeautifulSoup (saved webpage source codes into a local file)
body: <p>I am using Python 2.7 + BeautifulSoup 4.3.2.</p>
  
  <p>I am trying to use Python and BeautifulSoup to pick up information on a webpage. Because the webpage is in the company website and requires login and redirection, I copied the target page's source code page into a file and saved it as “example.html” in C:\ for the convenience of practicing.</p>
  
  <p>This is a part of the original code:</p>
  
  <pre><code>&lt;tr class="ghj"&gt;
      &lt;td&gt;&lt;span class="city-sh"&gt;&lt;sh src="./citys/1.jpg" alt="boy" title="boy" /&gt;&lt;/span&gt;&lt;a href="./membercity.php?mode=view&amp;amp;u=12563"&gt;port_new_cape&lt;/a&gt;&lt;/td&gt;
      &lt;td class="position"&gt;&lt;a href="./search.php?id=12563&amp;amp;sr=positions" title="Search positions"&gt;452&lt;/a&gt;&lt;/td&gt;
      &lt;td class="details"&gt;&lt;div&gt;South&lt;/div&gt;&lt;/td&gt;
      &lt;td&gt;May 09, 1997&lt;/td&gt;
      &lt;td&gt;Jan 23, 2009 12:05 pm&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>The code I worked out so far is:</p>
  
  <pre><code>from bs4 import BeautifulSoup
  import re
  import urllib2
  
  url = "C:\example.html"
  page = urllib2.urlopen(url)
  soup = BeautifulSoup(page.read())
  
  cities = soup.find_all('span', {'class' : 'city-sh'})
  
  for city in cities:
  print city
  </code></pre>
  
  <p>This is just the first stage of testing, so it's somewhat incomplete.</p>
  
  <p>However, when I run it, it gives an error message. Seems it’s improper to use <code>urllib2.urlopen</code> to open a local file.</p>
  
  <pre><code> Traceback (most recent call last):
     File "C:\Python27\Testing.py", line 8, in &lt;module&gt;
       page = urllib2.urlopen(url)
     File "C:\Python27\lib\urllib2.py", line 127, in urlopen
       return _opener.open(url, data, timeout)
     File "C:\Python27\lib\urllib2.py", line 404, in open
       response = self._open(req, data)
     File "C:\Python27\lib\urllib2.py", line 427, in _open
       'unknown_open', req)
     File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
       result = func(*args)
     File "C:\Python27\lib\urllib2.py", line 1247, in unknown_open
       raise URLError('unknown url type: %s' % type)
   URLError: &lt;urlopen error unknown url type: c&gt;
  </code></pre>
  
  <p>How can I practice using a local file?</p>