码迷,mamicode.com
首页 > 编程语言 > 详细

[python]爬虫学习(二)

时间:2016-11-12 22:30:28      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:pre   python   getc   --   erro   恢复   远程服务   url   error   

---恢复内容开始---

#python2

import urllib2

#python3

import urllib.request

html=urllib.request.urlopen(‘http://www.sogou.com‘)
print (html)

#<http.client.HTTPResponse object at 0x0000000002D84BA8
print (html.read())

 

urllib.request,

urllib.error,

urllib.parse,

urllib.robotparser四个子模块,

介绍urllib.request的简单用法.首先是urlopen函数,用于打开一个URL

  • info():返回一个对象,表示远程服务器返回的头信息。
  • getcode():返回Http状态码,如果是http请求,200表示请求成功完成;404表示网址未找到。
  • geturl():返回请求的url地址。

[python]爬虫学习(二)

标签:pre   python   getc   --   erro   恢复   远程服务   url   error   

原文地址:http://www.cnblogs.com/lfqcode/p/6057411.html

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