为什么这个会替换成空行呢?
import urllib.request
url="http://www.baidu.com"
Request=urllib.request.urlopen(url)
print(type(Request.read()))
print(Request.read().decode('utf-8'))
print('123456')
<class 'bytes'>
123456
将type那行注释掉或者讲那行移动到print(Request.read().decode('utf-8'))下面就可以了
response对象不能读取2次,第二次再读取没有数据了所以打印空行,要做其他操作可以读取数据到变量中,操作变量就行了
import urllib.request
url="http://www.baidu.com"
Request=urllib.request.urlopen(url)
data=Request.read()
print(type(data))
print(data.decode('utf-8'))
print('123456')
是 print(Request.read().decode('utf-8'))
这行代码打印出来就是空值, 所以会有个空行