写 Python 爬虫的助手

写爬虫变成了这样:

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 ¶

安装:

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

或者直接 clone 进自己的脚本目录,再解决requestspyquery两个依赖

更多信息:

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

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

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

    原文作者:eric
    原文地址: https://segmentfault.com/a/1190000003841583
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞