我写了一个潦草的潦草者试图收集http://www.shop.ginakdesigns.com/main.sc上的项目
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from scrapy.selector import Selector
from .. import items
class GinakSpider(CrawlSpider):
name = "ginak"
start_urls = [
"http://www.shop.ginakdesigns.com/main.sc"
]
rules = [Rule(SgmlLinkExtractor(allow=[r'category\.sc\?categoryId=\d+'])),
Rule(SgmlLinkExtractor(allow=[r'product\.sc\?productId=\d+&categoryId=\d+']), callback='parse_item')]
def parse_item(self, response):
sel = Selector(response)
self.log(response.url)
item = items.GinakItem()
item['name'] = sel.xpath('//*[@id="wrapper2"]/div/div/div[1]/div/div/div[2]/div/div/div[1]/div[1]/h2/text()').extract()
item['price'] = sel.xpath('//*[@id="listPrice"]/text()').extract()
item['description'] = sel.xpath('//*[@id="wrapper2"]/div/div/div[1]/div/div/div[2]/div/div/div[1]/div[4]/div/p/text()').extract()
item['category'] = sel.xpath('//*[@id="breadcrumbs"]/a[2]/text()').extract()
return item
然而,它不会超出主页进入任何链接。我尝试了各种方法,也检查了SgmlLinkExtractor的正则表达式。有什么问题吗?你知道吗
问题是有
jsessionid
插入到您试图提取的链接中,例如:通过对任何字符使用
.*?
非贪婪匹配而不是查找/?
来修复它:希望有帮助。你知道吗
相关问题 更多 >
编程相关推荐