準(zhǔn)備環(huán)境:
一、pip list :查看python2.7當(dāng)前安裝哪些包
二、安裝必須的包,如存在此步驟略過(guò)
lxml:pip install lxml==3.4.2
setuptools
OpenSSL
三、安裝scrapy
pip install scrapy
四、pip list:查看需要的包是否安裝
注:
windows端安裝遇到的問(wèn)題

圖上是由于缺少VCForPython27導(dǎo)致,下載安裝即可
2.cmd程序最好以管理員身份運(yùn)行,以免出現(xiàn)不必要的麻煩
scrapy使用步驟
1.生成項(xiàng)目
scrapy startproject project_name
cd project_name
2.生成代碼框架
scrapy genspider example example.com
3編寫(xiě)數(shù)據(jù)收集方面的代碼
4.執(zhí)行代碼
scrapy crwal example
-- coding: utf-8 --import scrapy
class AmoebaSpider(scrapy.Spider):
#name:用于區(qū)別不同的Spider,要求唯一 ,也是scrapy genspider Spider1 example.com命令中的 Spider1
name = "amoeba"
allowed_domains = ["amoeba.com"]
#start_urls包含Spider在啟動(dòng)時(shí)進(jìn)行爬取的url列表
start_urls = ( 'http://www.amoeba.com/', )
#spider的一個(gè)方法,url下載完成后的Response對(duì)象作為唯一參數(shù)傳給該函數(shù),
# parse方法的功用:
# 1.負(fù)責(zé)解析返回的數(shù)據(jù):
# 2.提取數(shù)據(jù)(生成Item);
# 3.生成需要進(jìn)一步處理的Request對(duì)象
def parse(self, response):
pass
