[問題] 從網頁抓資料,中文處理上的問題
我的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 就會亂亂的
故發文求解惑
謝謝大家
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.119.164.134
※ 文章網址: http://www.ptt.cc/bbs/Python/M.1414239194.A.6AB.html
→
10/25 20:53, , 1F
10/25 20:53, 1F
※ 編輯: elmo56 (140.119.164.134), 10/25/2014 20:56:23
→
10/25 20:54, , 2F
10/25 20:54, 2F
※ 編輯: elmo56 (140.119.164.134), 10/25/2014 21:01:51
→
10/25 21:09, , 3F
10/25 21:09, 3F
→
10/25 21:12, , 4F
10/25 21:12, 4F
→
10/25 21:19, , 5F
10/25 21:19, 5F
→
10/25 22:01, , 6F
10/25 22:01, 6F
→
10/26 00:14, , 7F
10/26 00:14, 7F
→
10/26 01:10, , 8F
10/26 01:10, 8F
推
11/02 14:34, , 9F
11/02 14:34, 9F
→
11/02 14:35, , 10F
11/02 14:35, 10F