1、所需软件:eclipse、pydev插件、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
百度了这个错误解决方法也没解决,也不造怎么回事了。。