GVKun编程网logo

如何在一个Scrapy项目中为不同的Spider使用不同的管道(scrapy 多个spider)

22

在这里,我们将给大家分享关于如何在一个Scrapy项目中为不同的Spider使用不同的管道的知识,让您更了解scrapy多个spider的本质,同时也会涉及到如何更有效地android–如何为不同的密

在这里,我们将给大家分享关于如何在一个Scrapy项目中为不同的Spider使用不同的管道的知识,让您更了解scrapy 多个spider的本质,同时也会涉及到如何更有效地android – 如何为不同的密度指定不同的布局尺寸、Android:如何为不同的Android版本使用不同的主题?、c – 如何在不创建新配置的情况下,为两个不同解决方案使用的一个项目使用不同的#defines、c# – 在Visual Studio 2010中为不同的构建平台使用不同的引用?的内容。

本文目录一览:

如何在一个Scrapy项目中为不同的Spider使用不同的管道(scrapy 多个spider)

如何在一个Scrapy项目中为不同的Spider使用不同的管道(scrapy 多个spider)

我有一个令人毛骨悚然的项目,其中包含多个蜘蛛。我有什么方法可以定义为哪个蜘蛛使用哪个管道?并非我定义的所有管道都适用于每个蜘蛛。

谢谢

答案1

小编典典

在Pablo Hoffman的解决方案的基础上,您可以在process_itemPipeline对象的方法上使用以下装饰器,以便它检查pipeline您的Spider的属性是否应执行。例如:

def check_spider_pipeline(process_item_method):    @functools.wraps(process_item_method)    def wrapper(self, item, spider):        # message template for debugging        msg = ''%%s %s pipeline step'' % (self.__class__.__name__,)        # if class is in the spider''s pipeline, then use the        # process_item method normally.        if self.__class__ in spider.pipeline:            spider.log(msg % ''executing'', level=log.DEBUG)            return process_item_method(self, item, spider)        # otherwise, just return the untouched item (skip this step in        # the pipeline)        else:            spider.log(msg % ''skipping'', level=log.DEBUG)            return item    return wrapper

为了使此装饰器正常工作,蜘蛛程序必须具有管道属性,其中包含要用于处理项目的管道对象的容器,例如:

class MySpider(BaseSpider):    pipeline = set([        pipelines.Save,        pipelines.Validate,    ])    def parse(self, response):        # insert scrapy goodness here        return item

然后在一个pipelines.py文件中:

class Save(object):    @check_spider_pipeline    def process_item(self, item, spider):        # do saving here        return itemclass Validate(object):    @check_spider_pipeline    def process_item(self, item, spider):        # do validating here        return item

所有Pipeline对象仍应在ITEM_PIPELINES中的设置中进行定义(以正确的顺序进行更改-这样很好,以便可以在Spider上指定顺序)。

android – 如何为不同的密度指定不同的布局尺寸

android – 如何为不同的密度指定不同的布局尺寸

你能否告诉我如何指定不同密度屏幕的布局尺寸?
即,不同密度的布局是相同的,但是某些尺寸是不同的.
我怎样才能做到这一点?

谢谢.

解决方法:

//1.create different dimens.xml in different resource folders as below 

 res/values-ldpi/dimens.xml
 res/values-mdpi/dimens.xml
 res/values-hdpi/dimens.xml

 //Then Android will decide which file to use. 

//2.Create  dimensions values in respective dimens.xml file according to the need as below


 <!-- in values-ldpi/dimens.xml -->
 <dimen name="textSize">25dip</dimen>

// and..

 <!-- in values-mdpi/dimens.xml -->
 <dimen name="textSize">20dip</dimen>

// etc. 
// 3.Don't care about resolution Android will take care of which resource to fetch.
// 4.Mention size in  dp instead of pixels.

Android:如何为不同的Android版本使用不同的主题?

Android:如何为不同的Android版本使用不同的主题?

MinSDKVersion = 7
TargetSDKVersion = 17

如果用户拥有SDKVersion 11或更高版本,我想将主题设置为Theme.Holo.Light.
它在这里对我不起作用.当我在3.1设备上启动应用程序时,它只使用Theme.Light:

当我在版本低于3.1的设备上运行此应用程序时也是如此

我的文件夹结构:

表现:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/MyTheme" >

值-V11:

<resources>

<!--
    Base application theme,dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@android:style/Theme.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml,while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Light">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>


<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>

其他值文件夹:

<resources>

<!--
    Base application theme,while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Light">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

    <style name="MyTheme" parent="@android:style/Theme.Light">
    <!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>

我怎样才能正确使用它?

诚挚
marco Seiz

解决方法

为什么在styles.xml文件中有两次主题?
<style name="AppTheme" parent="@android:style/Theme.Light">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>


<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>

删除不需要的那个(在本例中为Theme.Light主题):

值-V11:

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>

值:

<style name="MyTheme" parent="@android:style/Theme.Light">
    <!-- Any customizations for your app running on devices with Theme.Holo here -->
</style>

c – 如何在不创建新配置的情况下,为两个不同解决方案使用的一个项目使用不同的#defines

c – 如何在不创建新配置的情况下,为两个不同解决方案使用的一个项目使用不同的#defines

这适用于Visual Studio 2015,C

我有一个项目编译为库,并有一些#if – #else语句

#ifdef DXTK
  //...
#elif defined DXUT
  //...
#else
  //...
#endif

我有两个不同的解决方案(每个都有一个单独的可执行项目),它们都将此库作为项目包含在内.

我需要在一个可执行项目中#define DXUT,在另一个项目中#define DXTK

但问题是,我在可执行项目(而不是库)的预处理器中的定义不会影响库项目的#if – #else语句

我知道一个建议是为库项目创建不同的配置,并使用一对一的解决方案,而另一个解决方案.

但有没有办法在整个解决方案中传递预处理器定义?

我尝试将/ DDXUT添加到C/C++ – >可执行项目的命令行,但它没有工作.

如何在不为每个项目创建新配置的情况下执行此操作?

解决方法

可能重复: Are Preprocessor Definitions compiled into a library?

简短的回答是“否”,如果没有不同的配置,你就无法做你想做的事情,因为在你将库包含到另一个项目之前,已经转换了编译到该库中的代码.

c# – 在Visual Studio 2010中为不同的构建平台使用不同的引用?

c# – 在Visual Studio 2010中为不同的构建平台使用不同的引用?

如何设置VS2010项目,以便根据所选平台使用不同的引用?
实际上,当我选择x86作为平台时,我想链接一个32位库,但当我选择x64时,我想链接一个32位库.

有关如何为C#VS2010项目完成此交换的任何想法?

解决方法

没有尝试过,但可能你需要编辑项目文件并使用引用将条件入侵到ItemGroup中.

在这里,你找到一个SO问题here的答案.

今天关于如何在一个Scrapy项目中为不同的Spider使用不同的管道scrapy 多个spider的分享就到这里,希望大家有所收获,若想了解更多关于android – 如何为不同的密度指定不同的布局尺寸、Android:如何为不同的Android版本使用不同的主题?、c – 如何在不创建新配置的情况下,为两个不同解决方案使用的一个项目使用不同的#defines、c# – 在Visual Studio 2010中为不同的构建平台使用不同的引用?等相关知识,可以在本站进行查询。

本文标签: