在深处爬行不起作用

2024-10-01 02:37:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在写破烂的代码爬行的第一页和一个额外的深度给定的网页

不知怎么的,我的爬虫没有进入额外的深度。只是抓取给定的起始URL并结束其操作。在

我甚至连获取链接的规则都被忽略了。什么是可能的原因,我能改变什么使它遵循规则

import scrapy
from scrapy.contrib.spiders import CrawlSpider, Rule
from crawlWeb.items import CrawlwebItem
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
class DmozSpider(CrawlSpider):
name = "premraj"
start_urls = [
    "http://www.broadcom.com",
    "http://www.qualcomm.com"
]
rules = [Rule(SgmlLinkExtractor(), callback='parse',process_links="process_links",follow=True)]
def parse(self, response):
    #print dir(response)
    #print dir(response)
    item=CrawlwebItem()

    item["html"]=response.body
    item["url"]=response.url
    yield item
def process_links(self,links):
    print links
    print "hey!!!!!!!!!!!!!!!!!!!!!"

Tags: fromimporthttp规则responselinksitemcontrib
1条回答
网友
1楼 · 发布于 2024-10-01 02:37:39

CrawlSpider documentation中有一个警告框。上面写着:

When writing crawl spider rules, avoid using parse as callback, since the CrawlSpider uses the parse method itself to implement its logic. So if you override the parse method, the crawl spider will no longer work.

您的代码可能无法按预期工作,因为您确实使用了parse作为回调函数。在

相关问题 更多 >