1. 程式人生 > >python爬蟲環境搭建

python爬蟲環境搭建

1、所需軟體:eclipsepydev外掛、python安裝包

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方法了。

百度了這個錯誤解決方法也沒解決,也不造怎麼回事了。。