def parse(self, response):
item = StockItem()
print "===============上海================"
stocks_sh = response.css('div#quotesearch ul li a[href*="http://quote.eastmoney.com/sh"]::text')
for stock in stocks_sh:
item['stock_id'] = 's_sh' + re.findall('\((.*?)\)', stock.extract())[0]
yield item
print "===============深圳================"
stocks_sz = response.css('div#quotesearch ul li a[href*="http://quote.eastmoney.com/sz"]::text')
for stock in stocks_sz:
item['stock_id'] = 's_sz' + re.findall('\((.*?)\)', stock.extract())[0]
yield item
复制代码
玄机尽在response.css('div#quotesearch ul li a[href*="http://quote.eastmoney.com/sh"]::text’),使用了css来过滤自己需要的数据。