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

yipeiwu_com6年前Python基础

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

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程序设计有所帮助。

相关文章

Linux上安装Python的PIL和Pillow库处理图片的实例教程

安装 正常情况,只需 pip install PIL==1.1.7 或者 pip install Pillow==2.9.0 即可。但需留意安装后的输出 安装完成后,需留意输...

python3编写ThinkPHP命令执行Getshell的方法

python3编写ThinkPHP命令执行Getshell的方法

加了三个验证漏洞以及四个getshell方法 # /usr/bin/env python3 # -*- coding: utf-8 -*- # @Author: Morker #...

Python logging模块学习笔记

模块级函数 logging.getLogger([name]):返回一个logger对象,如果没有指定名字将返回root loggerlogging.debug()、logging.in...

Python搭建Spark分布式集群环境

Python搭建Spark分布式集群环境

前言 Apache Spark 是一个新兴的大数据处理通用引擎,提供了分布式的内存抽象。Spark 最大的特点就是快,可比 Hadoop MapReduce 的处理速度快 100 倍。本...

将matplotlib绘图嵌入pyqt的方法示例

我的终极整理,供参考 # coding:utf-8 import matplotlib # 使用 matplotlib中的FigureCanvas (在使用 Qt5 Backends...