本文实例讲述了
python
打开url并按指定块读取网页内容的方法。分享给大家供大家参考。具体实现方法如下:
希望本文所述对大家的Python程序设计有所帮助。
Python 3.14.3
微软官方的 Python 扩展,是 VS Code 安装量最高的扩展(209M+)。集成 IntelliSense(通过 Pylance)、调试(通过 Python Debugger)、代码检查、格式化、重构和单元测试等功能。支持 Jupyter Notebook、虚拟环境管理和多 Python 版本切换。
下载
import urllib
pagehandler = urllib.urlopen("http://www.baidu.com")
outputfile = open("index.html", "wb")
while 1:
data = pagehandler.read(512)
if not data:
break
outputfile.write(data)
outputfile.close()
pagehandler.close()