作者:
elmo56 (小樹芽)
2014-10-25 20:13:12我的python 是2.7版
是用beautifulsoup 去抓網頁資料
抓到了table裡面的值
例如 a[2]= <td> 雅虎新聞 Yahoo news </td>
a[3]= <td> 四 thr </td>
我也透過 a[2]=a[2].get_text()
把tag給去掉
只留下 text的部分
若我現在 print a[2],a[3]
結果: 雅虎新聞 Yahoo news 四 thr
但現在問題是
若我設一個 newslist=[]
再把 newslist.append(a[2])
newslist.append(a[3])
在print newslist
結果會變成 中文字是亂碼
英文是正常的
單獨印出那個位置的時候 正常
printf newslist[0] 會顯示 雅虎新聞 Yahoo news
printf newslist 會變成 u'\u4eda\u623f\u4eds\ Yahoo news u'\u4dsw thr
上面編碼是我亂打的但會是這樣的情況
要印出整個list 或是dict 就會亂亂的
故發文求解惑
謝謝大家