新建项目和crawlspider爬虫

1
2
3
4

scrapy startproject shopping
cd shopping
scrapy genspider -t crawl jollychic www.jollychic.com

设置settings.py 项目的路径

1
2
3
4
5
import sys
import os
project_dir = os.path.abspath(os.path.dirname(__file__))
BASE_DIR = os.path.dirname(os.path.abspath(os.path.dirname(__file__)))
sys.path.insert(0, os.path.join(BASE_DIR, 'shopping'))

items.py

1
2
3
4
5
6
7
8
from scrapy import Item, Field
from scrapy.loader import ItemLoader


class JollychicItemLoader(ItemLoader):
default_output_processor = TakeFirst()
class JollychicItem(Item):
title = Field()

spiders/jollychic.py

1
2
3
4
5
6
7
from item import JollychicItemLoader, JollychicItem

def parse(self, response):
item_loader = JollychicItemLoader(item=JollychicItem, response=reponse)
item_loader.add_css()
item = item_loader.load_item()
return item

×

纯属好玩

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

文章目录
,