javascript - scrpy CrawlSpider自動爬去網頁問題

來源:互聯網
上載者:User
#My Code如下,問題在代碼的注釋裡面
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'這是誰?????????????????????'    

回複內容:

#My Code如下,問題在代碼的注釋裡面
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,}")), #此處要注意?號的轉換,複製過來需要對?號進行轉義。

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.