安裝
pip install pyspider命令行運行 pyspider瀏覽器運行腳本編輯界面WebUI http://localhost:5000/
如果你使用的是ubuntu系統(tǒng),嘗試:
apt-get install python python-dev python-distribute python-pip \
libcurl4-openssl-dev libxml2-dev libxslt1-dev python-lxml \
libssl-dev zlib1g-dev
先去安裝二進制的包
如果需要請安裝PhantomJS http://phantomjs.org/build.html
應該注意PhantomJS只有把啟動路徑添加到系統(tǒng)環(huán)境中才能使用。
注意:pyspider命令是默認啟動所all模型,該模型是使用線程和子進程的。有關生產(chǎn)環(huán)境的,請轉(zhuǎn)到鏈接Deployment閱讀
警告:腳本編輯界面WebUI,是對外開放的。這會對你的電腦造成不必要的風險,請在內(nèi)網(wǎng)下使用它。
from pyspider.libs.base_handler import *
class Handler(BaseHandler):
crawl_config = {
}
@every(minutes=24 * 60)
def on_start(self):
self.crawl('http://scrapy.org/', callback=self.index_page)
@config(age=10 * 24 * 60 * 60)
def index_page(self, response):
for each in response.doc('a[href^="http"]').items():
self.crawl(each.attr.href, callback=self.detail_page)
@config(priority=2)
def detail_page(self, response):
return {
"url": response.url,
"title": response.doc('title').text(),
}
你可以調(diào)試你的腳本一步一步的點擊run按鈕。轉(zhuǎn)到follows儀表盤,點擊play按鈕,去繼續(xù)。
更多建議: