[python]爬虫学习(二)

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

#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地址。
原文地址:https://www.cnblogs.com/lfqcode/p/6057411.html