脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - python打开url并按指定块读取网页内容的方法

python打开url并按指定块读取网页内容的方法

2020-06-17 10:24重负在身 Python

这篇文章主要介绍了python打开url并按指定块读取网页内容的方法,涉及Python操作URL及网页内容的技巧,非常具有实用价值,需要的朋友可以参考下

本文实例讲述了python打开url并按指定块读取网页内容的方法。分享给大家供大家参考。具体实现方法如下:

?
1
2
3
4
5
6
7
8
9
10
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()

希望本文所述对大家的Python程序设计有所帮助。

延伸 · 阅读

精彩推荐