创建 scrapy
项目
我们一般采用这种方式:
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
➜ <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
|
我推荐采用这种方式:
2. scrapy3 startproject project demo
1
2
|
2.
scrapy3
startproject
project
demo
|
➜ 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 呢?
创建一个模板
scrapy3 genspider seo www.168seo.cn
1
2
|
scrapy3
genspider
seo
www
.
168seo.cn
|
如何运行呢?
➜ 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 scrapy scrapy3 runspider seo.py
1
2
|
➜
python
scrapy
scrapy3
runspider
seo
.
py
|
这样就可以运行脚本了