scrapy获取URL为: http://product.dangdang.com/1259526222.html
想获取型号获取不到,想问下大家怎么获取?
1、希望brand返回的是只包括型号的div;
2、希望通过xpath就可以获取;
在scrapy shell中测试是可以的,但是到了编写的时候就拿不到了。。。。
代码:
>#coding:cp936
from scrapy.spider import BaseSpider
from scrapy.selector import Selector
class dangdang(BaseSpider):
 name='dangdang'
 allowed_domains=[]
 start_urls=['http://product.dangdang.com/1259526222.html']
 def parse(self,response):
  sel=Selector(response)
  title=sel.xpath('//div[@class="head"]/h1/text()').extract()
  brand='\\u54c1\\u724c'.decode('unicode_escape')#型号
  brand=sel.xpath(('//div[@class="mall_goods_foursort_style_frame" and contains(text(),%s)]/a/text()')%(brand)).extract()
想获取型号获取不到,想问下大家怎么获取?
1、希望brand返回的是只包括型号的div;
2、希望通过xpath就可以获取;
在scrapy shell中测试是可以的,但是到了编写的时候就拿不到了。。。。
代码:
>#coding:cp936
from scrapy.spider import BaseSpider
from scrapy.selector import Selector
class dangdang(BaseSpider):
 name='dangdang'
 allowed_domains=[]
 start_urls=['http://product.dangdang.com/1259526222.html']
 def parse(self,response):
  sel=Selector(response)
  title=sel.xpath('//div[@class="head"]/h1/text()').extract()
  brand='\\u54c1\\u724c'.decode('unicode_escape')#型号
  brand=sel.xpath(('//div[@class="mall_goods_foursort_style_frame" and contains(text(),%s)]/a/text()')%(brand)).extract()