环境:python 2.7
坑:urlopen链接读取后就要转,不能用bs解析后再转:
url = "http://kfc.xixik.com/shop/shanghai/kfc"
html = urllib.urlopen(url).read().decode('gbk')
bsObj = BeautifulSoup(html, "html.parser")
address = bsObj.find('div', {'class': 'couponAddress'}).get_text()
address_utf8 = address.encode('utf-8')
print address_utf8