我正在尝试使用scrapy从网页上抓取产品信息.我的待删节网页如下所示:
我试图复制next-button-ajax-call但是无法正常工作,所以我试试了selenium.我可以在一个单独的脚本中运行selenium的webdriver,但我不知道如何与scrapy集成.我应该把硒部分放在我的scrapy蜘蛛里?
我的蜘蛛非常标准,如下所示:
class ProductSpider(CrawlSpider):
name = "product_spider"
allowed_domains = ['example.com']
start_urls = ['http://example.com/shanghai']
rules = [
Rule(SgmlLinkExtractor(restrict_xpaths='//div[@id="productList"]//dl[@class="t2"]//dt'), callback='parse_product'),
]
def parse_product(self, response):
self.log("parsing product %s" %response.url, level=INFO)
hxs = HtmlXPathSelector(response)
# actual data follows
Run Code Online (Sandbox Code Playgroud)
任何想法都表示赞赏.谢谢!
我希望sentry/raven忽略来自某个函数或django模块的所有异常,但是查看文档和代码,我只看到一个选项,通过向其添加一个额外的属性来忽略自定义异常.有没有办法忽略函数名称或模块名称的异常?谢谢!
我遇到了类似于 如何在Django中查询基于抽象类的对象的问题? 该线程建议使用multi_table_inheritance.我个人认为使用content_type在概念上更舒服(感觉更接近逻辑,至少对我而言)
使用上一个链接中的示例,我只需添加一个StelarType
class StellarType(models.Model):
"""
Use ContentType so we have a single access to all types
"""
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
Run Code Online (Sandbox Code Playgroud)
然后将其添加到抽象基础模型中
class StellarObject(BaseModel):
title = models.CharField(max_length=255)
description = models.TextField()
slug = models.SlugField(blank=True, null=True)
stellartype = generic.GenericForeignKey(StellarType)
class Meta:
abstract = True
Run Code Online (Sandbox Code Playgroud)
要在StellarObject和StellarType之间进行同步,我们可以连接post_save信号,以便在每次创建Planet或Star时创建StellarType实例.通过这种方式,我可以通过StellarType查询StellarObjects.所以我想知道使用这种方法反对使用multi_table_inheritance的PRO和CON是什么?我认为两者都在数据库中创建了一个额外的表.但是数据库性能呢?可用性/灵活性如何?感谢您的任何投入!