Giter Site home page Giter Site logo

spider_python's Introduction

spider_python

Edited by huWANG

##概述

原版是用於抓取北郵人論壇和水木社區校招信息的爬蟲程序。 俱有手機短信通知功能,需要在conf.py里配置139手機號,發件箱賬號和密碼。(短信通知功能也可作為郵件通知功能)。

不支持Python3。

##策略

###爬蟲爬取 爬取模塊默認每1小時運行1次,同時抓取web_urls和current_message_urls。 每爬取10次清空所有數據。

###發送短信 發短信模塊默認每10分鐘掃描一次current_message_urls,不為空才會發短信。 發送成功後會把current_message_urls合併到outdated_message_urls中,並清空current_message_urls。

###關鍵詞篩選 在conf.py里根據自己的興趣定制篩選的關鍵詞,抓取你想要的信息:

  • WEB_FILTER_XXX_KEYS是針對Web頁面抓取的關鍵詞
  • MESSAGE_FILETER_XXX_KEYS是針對短信及郵件通知的關鍵詞

包含XXX_FILETER_PRI_KEYS的鏈接一定會被抓取。
包含XXX_FILETER_KEYS且不包含XXX_FILETER_EXCLUDE_KEYS的鏈接也會被抓取。

###關鍵詞篩選測試樣例 設置如下:

  • WEB_FILETER_PRI_KEYS = (u'校招', u'應屆', u'畢業生')
    
  • WEB_FILETER_KEYS = (u'百度', u'阿里', u'騰訊',u'網易')
    
  • WEB_FILETER_EXCLUDE_KEYS = (u'社招',)
    

測試結果如下:

"[社招/校招] 阿里巴巴招聘實習生" # True,信息包含WEB_FILETER_PRI_KEYS 

"[社招] 阿里巴巴招聘實習生" # False,信息雖包含WEB_FILETER_KEYS但也包含WEB_FILETER_EXCLUDE_KEYS 

"阿里巴巴招聘實習生" # True,信息雖包含WEB_FILETER_KEYS且不包含WEB_FILETER_EXCLUDE_KEYS 

###爬取目標的設置 本程序默認爬取北郵和水木兩個BBS板塊的信息,如果你還想爬取其他目標的信息,要在conf.py中HTTP_QUERYS元組內添加新網站設置信息的字典項。 下面示例添加了爬取'天津大學就業指導中心的招聘信息板塊'的設置:

{
    'host' : 'http://job.tju.edu.cn/', #網站的域名,'host'+'href'應該能夠合成為一個可訪問的招聘信息的鏈接。
    'url'  : 'http://job.tju.edu.cn/zhaopinxinxi.php', #設置你要爬取的頁面,該頁麵包含了招聘信息的鏈接,通常為招聘板塊的首頁。
    'headers' : {	                   #headers的設置保持不變
        "X-Requested-With" : "XMLHttpRequest",
     },
    'href' : r"^zhaopinxinxi_detail.php\?id=\d+$", #設置匹配字符串,匹配'url'網頁中<a>標籤的href內容。設置本項時可以在'url'網頁中找一條招聘信息的超鏈接<a>,將其中的href內容放入字符串,href尾部數字部分用'\d+'代替,如果鏈接中有'?',需要改成'\?'進行轉義。
    'source' : u'天津大學就業指導中心-招聘信息',
},

##安裝與運行 Unix/Windows下均需要先在本機安裝redis服務程序,然後在Unix下運行redis-server,在Windows下啓動redis-server.exe。

安裝示例:Mac OS X下安裝redis

brew install redis

此外,程序依賴以下Python第三方包:

安裝示例:Mac OS X/Linux下安裝Python第三方包

pip install apscheduler
pip install BeautifulSoup
pip install redis
pip install requests

然後直接運行main.py程序,訪問http://127.0.0.1:8888 -e 與 -s 參數分別開啓 郵件與短信通知功能,具體可以python main.py help 查看

##WEB頁面效果

1

Enjoy it。

spider_python's People

Contributors

lzrak47m4a1 avatar xiyoulaoyuanjia avatar mmoonzhu avatar itomsawyer avatar dasprojektz avatar

Watchers

James Cloos avatar huwung avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.