你的 In [76] 执行结果应该是 In [72] 的最后一段所以请试着完整的执行 In [72] 并对里面的content_container.text decode讲简单点:把 In [76] 的那行 print 取代掉 In [72] 的那行 print ...因为你写入一段后就马上把 file 关了所以你 for 循环里在做的事情是:1. 取得 content_container.text2. 开一个新的 file ("fuckyou123.txt")3. 写入 content_container.text4. 关闭 file ("fuckyou123.txt")由于 file open 的方式是 'w' (write),所以每次都会以一个新档案覆蓋掉原本的档案。又加上 file 的 open/close 都在同一个循环内,所以实际上这个 file 已经被覆写掉很多遍,直到最后一行结束。所以建议你把 file 的 open/close 移到循环外,循环内只负责写入资料。要先 open file ,再来写入资料,最后才 close file记得你的 `outfile.write(data)` 要放在循环内有解决问题就好,有空可以再看一下 with statementkey word: python with "context manager" "file open"keyword*
https://goo.gl/Fi9oKQ 直接贴给你好 XD上面连结的其他内容也可以多看看,希望对你有帮助!