我正在废弃一个网站,我在 scrapy 中编写了一个蜘蛛,但我可以使用以下方法提取产品价格:
hxs.select('//div[@class="product_list"]//div[@class="product_list_offerprice"]/text()').extract()
通过scrapy shell
但是当我试图对蜘蛛做同样的事情时,它返回的是空列表
这是我的蜘蛛代码:
from eScraper.items import EscraperItem
from scrapy.selector import HtmlXPathSelector
from scrapy.contrib.spiders import CrawlSpider
#------------------------------------------------------------------------------
class ESpider(CrawlSpider):
name = "ashikamallSpider"
allowed_domains = ["ashikamall.com"]
URLSList = []
for n in range (1,51):
URLSList.append('http://ashikamall.com/products.aspx?id=222&page=' + str(n))
start_urls = URLSList
def parse(self, response):
hxs = HtmlXPathSelector(response)
sites = hxs.select('//div[@class="product_list"]')
items = []
for site in sites:
item = EscraperItem()
item['productDesc'] = ""
item['productSite'] = "http://1click1call.com/"
item['productTitle'] = site.select('div[@class="product_list_name"]/h3/text()').extract()
item['productPrice'] = site.select('div[@class="product_list_offerprice"]/text()').extract()
item['productURL'] = "http://ashikamall.com/" + site.select('div[@class="product_list_image"]/a/@href').extract()[0].encode('utf-8')
item['productImage'] = "http://ashikamall.com/" + site.select('div[@class="product_list_image"]/a/img/@src').extract()[0].encode('utf-8')
items.append(item)
return items
这是我的 items.py
from scrapy.item import Item, Field
#------------------------------------------------------------------------------
class EscraperItem(Item):
image_urls = Field()
productURL = Field()
productDesc = Field()
image_paths = Field()
productSite = Field()
productTitle = Field()
productPrice = Field()
productImage = Field()
有人可以帮帮我吗?