python爬虫环境搭建

来源:互联网 发布:生死狙击矩阵视频 编辑:程序博客网 时间:2024/06/05 03:52

 

1、所需软件:eclipsepydev插件、python安装包

 

Eclipse:http://www.eclipse.org/downloads/

Pydev插件:http://sourceforge.net/projects/pydev/files/pydev/

Python安装包:https://www.python.org/downloads/

 

2、安装python安装包:

 

初学者可用shell编写Python:

 

 

3、把插件解压之后的文件合并到 eclipse目录里面:

插件解压后:

 

 

4、重启Eclipse

在Windows->preference里可以看到PyDev:

 

 

点击Interpreters里的Python Interpreter,指定Python压缩包的python.exe:

 

 

5、创建一个Python项目:

创建的项目:

 

6、设置编码:

点击Windows—>preferencesàGeneralàEditorsàText EditorsàSpelling

设置UTF-8编码:

 

 

右键刚才创建好的项目:

也设置为UTF-8编码:

 


 

7、编写一个简单的抓取网页代码:

import urllib

 

url="http://item.jd.com/1856581.html"

content=urllib.urlopen(url)

html=content.read().decode("gbk").encode("utf-8")

print html

 

print content.getcode()

print content.geturl()

print content.info()

content.close()

 

 

 

网页抓取成功,无乱码问题:

 

 

这样很快,一个小环境就搭建好了。

 

8、另注释:

最开始用的是在线安装Pydev插件,可是一直显示失败,所以就用离线安装Pydev方法了。

写入地址 http://pydev.org/updates

 

百度了这个错误解决方法也没解决,也不造怎么回事了。。



 

 

0 0