python代码:
import urllib.request
resp=urllib.request.urlopen('http://www.baidu.com')
html=resp.read()
file_object = open("test.txt","w")
file_object.write(html)
file_object.close()
报错:
Traceback (most recent call last):
File "D:\Code\Python\test\study.py", line 6, in
file_object.write(html)
TypeError: must be str, not bytes
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
python3.0跟2.7还是有挺大差别啊。
难怪楼主发urllib.request 没用过呢。。。
平时 写2.7, 用的是urllib和urlrlib2库