首页 > scrpy CrawlSpider自动爬去网页问题

scrpy CrawlSpider自动爬去网页问题

#我的代码如下,问题在代码的注释里面
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor as sle #用于定义需要提取的链接
class NewsSpider(CrawlSpider):

name = "demo2"
allowed_domains = ["360.cn"]
# start_urls=["http://bobao.360.cn/activity/index&page=2"]#这个连接测试成功
# rules = [ Rule(sle(allow=r'/vul/index?type=all&page=\d{1,3}'), follow=True,callback='parse_item1') ]#*这个测试不成功原因好像*
#allow=r'/vul/index?type=all&page=\d{1,3} 这个里面/vul/index?这个?有影响,请教如何修改
rules = [ Rule(sle(allow=r'/activity/index&page=\d{1,3}'), follow=True,callback='parse_item1') ]#这个连接测试成功

/activity/index&page=

def parse_item1(self, response):
    print u'这是谁?????????????????????'
    

此处要注意?号的转换,复制过来需要对?号进行转义。

网页中链接是这样:#/rwxwsblog/default.html?page=3"
要写成这样的:Rule(sle(allow=("/rwxwsblog/default.html\?page=\d{1,}")), #此处要注意?号的转换,复制过来需要对?号进行转义。

【热门文章】
【热门文章】