Scrapy第一个项目创建
作者:互联网
创建项目
- scrapy startproject +项目名称
- 项目树
.
│ scrapy.cfg
│
├─.idea
│ │ .gitignore
│ │ misc.xml
│ │ modules.xml
│ │ myspider.iml
│ │ workspace.xml
│ │
│ └─inspectionProfiles
│ profiles_settings.xml
│ Project_Default.xml
│
└─myspider
│ items.py
│ logging.md
│ middlewares.py
│ pipelines.py
│ scrapy.md
│ settings.py
│ init.py
│
├─spiders
│ │ book.py
│ │ init.py
│ │
│ └─__pycache__
│ book.cpython-38.pyc
│ init.cpython-38.pyc
│
└─__pycache__
middlewares.cpython-38.pyc
pipelines.cpython-38.pyc
settings.cpython-38.pyc
init.cpython-38.pyc
创建爬虫
- scrapy genspider [爬虫名称] [目标网址]
- 例如 scrapy genspider book paoshuzw.com
- 创建的爬虫文件为.py文件,储存在spides文件夹下
- book.py
import scrapy class TencentHrSpider(scrapy.Spider): name = 'book'# 爬虫名 allowed_domains = ['paoshuzw.com'] #允许爬虫范围 start_urls = ['http://www.paoshuzw.com/xiaoshuodaquan/'] # 最开始的url地址 def parse(self, response): # 处理start_urls地址对应的响应 pass
标签:xml,38,第一个,cpython,创建,py,scrapy,Scrapy,pyc 来源: https://www.cnblogs.com/zilinshisi/p/14453146.html