Python3访问并下载网页内容的方法

yipeiwu_com6年前Python基础

本文实例讲述了Python3访问并下载网页内容的方法。分享给大家供大家参考。具体如下:

#!/usr/local/bin/python3.2
import urllib.request,io,os,sys
req = urllib.request.Request("http://www.google.com")
f = urllib.request.urlopen(req)
s = f.read()
s = s.decode('gbk','ignore')
mdir = sys.path[0]+'/'
file = open(mdir+'admin6.txt','a',1,'gbk')
file.write(s)
file.close()

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

相关文章

python实现旋转和水平翻转的方法

如下所示: # coding=utf-8 import glob import os from PIL import Image def rotate_270(imgae):...

浅谈python字典多键值及重复键值的使用

浅谈python字典多键值及重复键值的使用

在python中使用字典,格式如下: dict={ key1:value1 , key2;value2 ...} 在实际访问字典值时的使用格式如下: dict[key] 多键值 字典的...

python实现读取大文件并逐行写入另外一个文件

<pre name="code" class="python">creazy.txt文件有4G,逐行读取其内容并写入monday.txt文件里。 def crea...

通过python实现windows桌面截图代码实例

这篇文章主要介绍了python实现windows桌面截图代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 代码实例 impo...

python 遍历字符串(含汉字)实例详解

python 遍历字符串(含汉字)实例详解 s = "中国china" for j in s: print j 首先一个,你这个'a'是什么编码?可能不是你所想的gbk &...