美文网首页爬虫
聚焦Python分布式爬虫必学框架 Scrapy 打造搜索引擎

聚焦Python分布式爬虫必学框架 Scrapy 打造搜索引擎

作者: 江湖十年 | 来源:发表于2018-07-07 14:04 被阅读22次

通过 CrawlSpider 创建爬虫

  • 在项目目录中,通过命令 scrapy genspider --list 查看 Scrapy 提供的所有爬虫模板,其中 basic 是默认模板
scrapy genspider --list
  • 通过命令 scrapy genspider -t crawl lagou www.lagou.com 创建拉钩网爬虫,其中 -t 参数用来指明创建爬虫所用模板
scrapy genspider -t crawl lagou www.lagou.com
image.png
  • 插入一个小技巧
image.png

要解决上述问题,只需在项目文件 settings.py 中加入如下两行代码即可

# 将 settings.py 所在路径配置到 Python Path
BASE_DIR = os.path.dirname(os.path.abspath(os.path.dirname(__file__)))
sys.path.append(os.path.join(BASE_DIR, 'ArticleSpider'))
image.png

相关文章

网友评论

    本文标题:聚焦Python分布式爬虫必学框架 Scrapy 打造搜索引擎

    本文链接:https://www.haomeiwen.com/subject/mvrseftx.html