寫 Python 爬蟲的助手

寫爬蟲變成了這樣:css

from gspider.base import BaseSpider
from gspider.fields import PQField


class PythonDocSpider(BaseSpider):
    title = PQField('h1')  # select `h1` element from the page, you can use other css selectors too
    content = PQField('p')
spider = PythonDocSpider(
    'https://docs.python.org/3/library/base64.html'
)

>>> print(spider.title)
>>> 19.6. base64 — Base16, Base32, Base64, Base85 Data Encodings ¶

安裝:html

git clone https://github.com/ericls/gspider
cd gspider
python setup.py install

或者直接 clone 進本身的腳本目錄,再解決requestspyquery兩個依賴python

更多信息:git

Project Name: Gspider. (Pretty random name, isn't it?)github

GitHub Repo: __https://github.com/ericls/gspider__web

原文:http://leeeric.com/post/a-python-web-crawler-helper/bash

相關文章
相關標籤/搜索