Using Python and BeautifulSoup (saved webpage source codes into a local file)
The best way to open a local file with BeautifulSoup is to pass it a file handler directly. http://www.crummy.com/software/BeautifulSoup/bs4/doc/#making-the-soup
from bs4 import BeautifulSoup
with open("C:\\example.html") as fp:
soup = BeautifulSoup(fp, 'html.parser')
for city in soup.find_all('span', {'class' : 'city-sh'}):
print(city)
With Chandan's help, the problem has been solved. All the credits shall go to him. :)
the "urllib2.url" is useless here.
from bs4 import BeautifulSoup
import re
# import urllib2
url = "C:\example.html"
page = open(url)
soup = BeautifulSoup(page.read())
cities = soup.find_all('span', {'class' : 'city-sh'})
for city in cities:
print city