解決方法一:
使用python的BeautifulSoup來抓取網頁然后輸出網頁標題,但是輸出的總是亂碼,找了好久找到解決辦法,下面分享給大家
首先是代碼
解決方法二:
BeautifulSoup在解析utf-8編碼的網頁時,如果不指定fromEncoding或者將fromEncoding指定為utf-8會出現中文亂碼的現象。
解決此問題的方法是將Beautifulsoup構造函數中的fromEncoding參數的值指定為:gb18030
page = urllib2.urlopen('//m.survivalescaperooms.com/');
soup = BeautifulSoup(page,fromEncoding="gb18030")
print soup.originalEncoding
print soup.prettify()
新聞熱點
疑難解答
圖片精選