#获取A股所有股票代码 class FinancialAnalysisSpider (scrapy.Spider):#定义Spider名称name ='stocks_Analysis'#限制Spider爬取的域名allowed_domains = ['www.eastmoney.com']start_urls =['http://87.push2.eastmoney.com/api/qt/clist/get?cb=jQuery112406526563715394427_1631116233755&pn=1&pz=10000&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&fid=f3&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23&fields=f12,f14']def parse(self,response):item=FinancialanalysisItem()#获取A股所有股票代码responsedata = response.texti =responsedata.count('f12')listdata = responsedata.split('diff\":')strdata = listdata[1].split('}}')[0]jsondata=json.loads(strdata)#print(jsondata)codelist=[]for j in range (0,i):stockcode=jsondata[j]['f12']codelist.append(stockcode)print(codelist)