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
然后一步一步装下去。 如果装的过程中,报错了。 就重新装。