# My code is as follows, the problem is in the code comment
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'这是谁?????????????????????'
Reply content:
# My code is as follows, the problem is in the code comment
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'这是谁?????????????????????'
It is important to note that the conversion of the number is to be escaped by copying the number.
The link in the webpage is this: #/rwxwsblog/default.html?page=3 "
It should be written like this: Rule (SLE (allow= ("/rwxwsblog/default.html\?page=\d{1,}")), the conversion of #此处要注意 number, and copying it requires escaping the number.