python 爬虫

python 爬虫课程

安装下载版本(https://www.python.org/downloads/release/python-2712/

默认会安装到C:\Python27目录下,配置环境变量Path

命令提示符测试 ,python
如下问题,环境变量未配置

python’不是内部或外部命令,也不是可运行的程序或批处理文件。

1.爬虫简介
2.简单爬虫架构
3.URL管理器
4.网页下载器(urllib2)
5.网页解析器(beautifulSoup)
6.爬取百度百科Python词条相关的数据

简介

  • python 爬虫意思:自动访问互联网自动提取数据
  • 互联网数据,为我所用!

简单爬虫架构

  • 爬虫调度端:监视状况.
    这里写图片描述

这里写图片描述

URL管理器

URL管理器:管理待抓取URL集合和已抓取URL集合
–防止重复抓取,防止循环抓取
这里写图片描述

URL实现方式

这里写图片描述

网页下载器(urllib2)

这里写图片描述

这里写图片描述

import urllib2, cookielib

url ="https://www.baidu.com/"
print "one"
response1=urllib2.urlopen(url)
print response1.getcode()
print len(response1.read())

这里写图片描述

print "two"
request=urllib2.Request(url);
request.add_header("user-agent","Mozilla/5.0")
response2=urllib2.urlopen(url)
print response2.getcode()
print len(response2.read())

这里写图片描述

print "three"
cj=cookielib.CookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
response3=urllib2.urlopen(url)
print response3.getcode()
print len(response3.read())

在Eclipse中安装pydev插件

http://www.cnblogs.com/Bonker/p/3584707.html

启动Eclipse, 点击Help->Install New Software… 在弹出的对话框中,点Add 按钮。 Name中填:Pydev, Location中填http://pydev.org/updates
然后一步一步装下去。 如果装的过程中,报错了。 就重新装。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值