當前位置: 首頁>>代碼示例>>Python>>正文


Python spiders.Rule方法代碼示例

本文整理匯總了Python中scrapy.spiders.Rule方法的典型用法代碼示例。如果您正苦於以下問題:Python spiders.Rule方法的具體用法?Python spiders.Rule怎麽用?Python spiders.Rule使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scrapy.spiders的用法示例。


在下文中一共展示了spiders.Rule方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: parse_body

# 需要導入模塊: from scrapy import spiders [as 別名]
# 或者: from scrapy.spiders import Rule [as 別名]
def parse_body(self, response):		
		global crawl_counter
		try:
			crawl_counter += 1
			if crawl_counter > max_crawl_limit:
				os._exit(0)
			matches = rules.match(data=response.body)
			if matches:
				for match in matches:
					print "[+] URL:", response.request.url, "Matched YARA Rule:", match
					if debug:
						print "[*] Matched body response:", response.body.decode("utf-8")
					txt = "URL: " + response.request.url + " Matched YARA Rule: " + str(match)
					log(txt)
		except Exception as e:
#			if debug:
			print str(e) 
開發者ID:mertsarica,項目名稱:hack4career,代碼行數:19,代碼來源:RedScanner.py

示例2: request_index

# 需要導入模塊: from scrapy import spiders [as 別名]
# 或者: from scrapy.spiders import Rule [as 別名]
def request_index(self, response):
        categories = list(set(response.css('#topMenuItem a::attr("href")').re('/([^\/]+)/$')))

        if self.category is not None:
            if self.category in categories:
                categories = [self.category]
            else:
                raise ValueError('invalid category slug. available slugs: %s' % ", ".join(categories))

        date_processing = self.start_date
        while date_processing <= self.end_date:
            for category in categories:
                # redifining the rule again according to the specific date url
                SamakalSpider.rules = (Rule(LinkExtractor(allow=('/' + date_processing.strftime('%Y/%m/%d') + '/\d+$',),
                                                          restrict_xpaths=('//div[@class="main-body"]')),
                                            callback="parse_content", follow=True),)
                super(SamakalSpider, self)._compile_rules()
                # http://bangla.samakal.net/-education/2016/06/01 
                url = 'http://bangla.samakal.net/{0}/{1}'.format(
                    category,
                    date_processing.strftime('%Y/%m/%d')
                )
                yield self.make_requests_from_url(url)
            date_processing += datetime.timedelta(days=1) 
開發者ID:banglakit,項目名稱:corpus-builder,代碼行數:26,代碼來源:samakal.py

示例3: __init__

# 需要導入模塊: from scrapy import spiders [as 別名]
# 或者: from scrapy.spiders import Rule [as 別名]
def __init__(self, domains, urls, *args, **kwargs):
        """Constructor for SiteSpider.

        Parameters
        ----------
        domains : list
            A list of domains for the site.
        urls : list
            A list of sitemap URLS of the site.
        href_xpaths : list
            A list of XPATH expression indicating the ancestors of `<a>`
            element.
        url_regex : string
            URL pattern regular expression.

        If you use this spider to store item into database, additional
        keywords are required:

        platform_id : int
            The id of a platform instance.
        session : object
            An instance of SQLAlchemy session.
        """
        self.session = kwargs.pop('session', None)
        self.platform_id = kwargs.pop('platform_id', None)
        self.url_regex = kwargs.pop('url_regex', None)
        self.href_xpaths = kwargs.pop('href_xpaths', ())
        self.start_urls = urls
        self.allowed_domains = domains
        self.rules = (Rule(
            LinkExtractor(
                allow_domains=self.allowed_domains,
                restrict_xpaths=self.href_xpaths,
                unique=True),
            callback="parse_item",
            follow=True),)

        super(SiteSpider, self).__init__(*args, **kwargs) 
開發者ID:IUNetSci,項目名稱:hoaxy-backend,代碼行數:40,代碼來源:url.py


注:本文中的scrapy.spiders.Rule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。