您的位置:首页 > 编程语言 > Python开发

【脚本语言系列】关于PythonWeb访问urllib,你需要知道的事

2017-05-10 13:31 651 查看

如何使用urllib

# -*- coding:utf-8 -*-
#
import Tkinter
import urllib
class Window:
def __init__(self, root):
self.root = root
self.entryUrl = Tkinter.Entry(root)
self.entryUrl.place(x = 5, y = 15)
self.get = Tkinter.Button(root, text = '下载页面', command = self.Get)
self.get.place(x = 120, y = 15)
self.edit = Tkinter.Text(root)
self.edit.place(y = 50)
def Get(self):
url = self.entryUrl.get()
page = urllib.urlopen(url)
data = page.read()
self.edit.insert(Tkinter.END, data)
page.close()
root = Tkinter.Tk()
window = Window(root)
root.minsize(600, 480)
root.mainloop()






试一下访问[示例网址](http://www.163.com



什么是urllib

使用Python的urllib模块可以创建一个简单的访问网站的脚本,获取指定的页面。

如果使用GUI库中显示HTML的组件,还可以制作一个简单的Python Web浏览器。

使用urllib进行简单地访问、下载页面内容。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐