如何单独使用scrapy

创建 scrapy 项目
我们一般采用这种方式:

Python
1. <span class="wp_keywordlink_affiliate"><a href="https://www.168seo.cn/tag/scrapy" title="View all posts in scrapy" target="_blank">scrapy</a></span>3 startproject demo
1
2
1. scrapy3 startproject demo
 

你会发现在demo下还有个demo,其实它的项目是第二个demo

Python
➜ <span class="wp_keywordlink"><a href="http://www.168seo.cn/python" title="python">python</a></span> <span class="wp_keywordlink_affiliate"><a href="https://www.168seo.cn/tag/scrapy" title="View all posts in scrapy" target="_blank">scrapy</a></span> tree ./ ./ └── demo ├── demo │   ├── __init__.py │   ├── __pycache__ │   ├── items.py │   ├── middlewares.py │   ├── pipelines.py │   ├── settings.py │   └── spiders │   ├── __init__.py │   └── __pycache__ └── scrapy.cfg 5 directories, 7 files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
➜    python scrapy tree . /
. /
└── demo
    ├── demo
    │   ├── __init__ . py
    │   ├── __pycache_ _
    │   ├── items . py
    │   ├── middlewares . py
    │   ├── pipelines . py
    │   ├── settings . py
    │   └── spiders
    │        ├── __init__ . py
    │        └── __pycache_ _
    └── scrapy . cfg
 
5 directories , 7 files
 

我推荐采用这种方式:

Python
2. scrapy3 startproject project demo
1
2
2. scrapy3 startproject project demo
 
Python
➜ python scrapy tree ./ ./ └── demo ├── project │   ├── __init__.py │   ├── __pycache__ │   ├── items.py │   ├── middlewares.py │   ├── pipelines.py │   ├── settings.py │   └── spiders │   ├── __init__.py │   └── __pycache__ └── scrapy.cfg 5 directories, 7 files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
➜    python scrapy tree . /
. /
└── demo
    ├── project
    │   ├── __init__ . py
    │   ├── __pycache_ _
    │   ├── items . py
    │   ├── middlewares . py
    │   ├── pipelines . py
    │   ├── settings . py
    │   └── spiders
    │        ├── __init__ . py
    │        └── __pycache_ _
    └── scrapy . cfg
 
5 directories , 7 files
 
 

如何单独使用 scrapy 呢?

创建一个模板

Python
scrapy3 genspider seo www.168seo.cn
1
2
scrapy3 genspider seo www . 168seo.cn
 

如何运行呢?

Python
➜ python scrapy ll total 8 -rw-r--r-- 1 songhao staff 217B 1 2 20:28 seo.py
1
2
3
4
➜    python scrapy ll
total 8
- rw - r -- r --    1 songhao   staff    217B    1    2 20 : 28 seo . py
 

可以这样

Python
➜ python scrapy scrapy3 runspider seo.py
1
2
➜    python scrapy scrapy3 runspider seo . py
 

这样就可以运行脚本了




  • zeropython 微信公众号 5868037 QQ号 5868037@qq.com QQ邮箱
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值