一個小專案(爬蟲)的誕生全過程

阿里貝爾發表於2016-06-13

下面是一個小爬蟲的整個誕生過程

step 1

在本地使用git管理工具:

mkdir Douban_Movie#建立並進入該目錄下
git init#初始化
vim readme.txt#在本檔案中寫入相關的必要資訊
git add readme.txt#新增
git commit -m ‘add comment’#提交到本地

step 2

在github上新建一個倉庫Douban_Movie後

git remote add origin git@github.com:icheli/Douban_Moive.git#或者git remote add origin https://github.com/ichenli/Douban_Movie.git   首次互動要建立連線
git push -u origin master#提交到github上,下載用git pull origin master

至此我們就知道如何將程式碼提交到github上了,下面我們所要做的就是程式設計了。

step3

在本地編寫程式之後就可以提交到本地git和github的伺服器上了

git add movie_crawler.py
git commit -m "this is the crawler"
git remote add origin git@git.com:ichenli/ZhiHu_movie.git#或者git remote add origin https://github.com/ichenli/ZhiHu_Movie.git(即github上專案的連結)
<pre name="code" class="python">git push -u origin master

有關程式的部分,已經放到github上了,程式其實很簡單,就是爬取了豆瓣上按類別的電影排序,爬取了其中前34個類別,例如愛情,喜劇,動畫等多種類別的電影,並依次獲取電影的ID,名稱,上映年份,型別,片長,分數,評價人數和劇情簡介。

step4

python3使用mysql資料庫需要pymysql包,據說還可以使用mysql-connector,但是沒用過,在https://pypi.python.org/pypi/PyMySQL3 下載pymysql包,cd進入目錄下

python3 setup.py install#安裝,好像需要管理員許可權

若在python3中能匯入pymysql包即代表成功,成功後就可以繼續程式設計啦!



:程式已經上傳到github上啦,https://github.com/ichenli/Douban_Movie,大家如果沒有安裝資料庫或者不想涉及資料庫,稍加修改即可執行,程式碼很簡單。


大家有什麼不懂的或者我哪兒寫錯了都歡迎留言!
















相關文章