1.創建項目:
? ? ? ? scrapy startproject mySpider
2.生成一個爬蟲:
? ? ? ? scrapy genspider itcast itcast.cn
3.提取數據:
? ? ? ? 根據網站結構在spider中實現數據采集相關內容
4.保存數據
? ? ? ? 使用pipeline進行數據后續處理和保存
1.創建項目
?
?items.py-->自己預計需要爬取的內容
middlewares.py-->自定義中間件的文件
pipelines.py-->管道,保存數據
settings.py-->設置文件,UA,啟動管道
spiders-->自己定義的spider的文件夾
2.創建爬蟲
scrapy startproject <爬蟲名字><允許爬取的域名>
?itcast.py-->定義spider的文件
import scrapyclass ItcastSpider(scrapy.Spider):name = "itcast"allowed_domains = ["itcast.cn"]start_urls = ["https://itcast.cn"]def parse(self, response):#定義對于網站的相關操作pass
爬蟲文件的介紹
三個參數
? ? ? ? name? ? ?allowed_domains? ? ? ?start_urls(設置起始的url,請求會被自動的發送出去,然后? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 返回parse方法做解析)
一個方法
? ? ? ? parse方法? ?—— 解析方法,通常用于起始url對于響應的解析
運行爬蟲需在爬蟲項目路徑下
scrapy crawl <爬蟲名字>??????
??