IDLE获取网页源码后print()后就卡死了

初学 python,所用的版本为 python3,参照网上在 IDLE 中写出了如下代码:

from urllib.request import urlopen

html = urlopen("http://tieba.baidu.com/")  
print(html.read().decode('utf-8'))  

然后 print() 之后 IDLE 虽然输出了,但是也就一直卡在这儿,如果不使用 print 而是将这个内容保存到文件是没问题的。请问是 IDLE 的问题,还是代码的问题,如何解决呢?

阅读 3.4k
1 个回答

可以试试先把内容存为变量。

lines = html.read().decode('utf-8').split()
for line in lines:
    print(line)
推荐问题