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

第一只python爬虫

时间:2016-09-09 14:55:08      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

import urllib.request
response = urllib.request.urlopen("http://www.baidu.com")
html = response.read()
html = html.decode(UTF-8)
print(html)

其中用 用urllib.request 中的urlopen打开百度(一定要加http,用read方法读取html代码,用 utf—8 解码。

技术分享

其中,response对象有一个getcode()方法,可以得到HTTP状态码(200为成功

技术分享

其中baidu能够正常访问,google访问超时,其中传入的三个参数:URL,向服务器发送的数据(没有为None,也可缺省),超时时间

返回的异常最后一句,timed out

 

第一只python爬虫

标签:

原文地址:http://www.cnblogs.com/Kurokey/p/5856267.html

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