码迷,mamicode.com
首页 > Web开发 > 详细

urllib模块

时间:2017-04-05 23:17:29      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:urlopen   cookies   ping   read   http请求   http   应用   api   pre   

urllib.request

1、定义

  用于打开URL的可扩展库,定义了基本和摘要式身份验证、重定向、cookies等应用中打开URL(主要是HTTP)的函数和类。

2、函数

  urllib.request.urlopen(url,data=None,url, data=None)

  url:网址

  data:若HTTP请求是GET则data为None,若为POSTdata必须有数据

  返回一个对象

from urllib.request import urlopen

html = urlopen("http://pythonscraping.com/pages/page1.html")
print(html.read())

urllib.error

1、定义

  由urllib.request引发的异常类,基本异常类是URLError

2、函数

  exception urllib.error.URLError

  exception urllib.error.HTTPError

  exception urllib.error.ContenTooShortError(msg, content)

urllib模块

标签:urlopen   cookies   ping   read   http请求   http   应用   api   pre   

原文地址:http://www.cnblogs.com/jp-mao/p/6671059.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!