美文网首页
scrapy.Request 爬中爬

scrapy.Request 爬中爬

作者: 心愿2016 | 来源:发表于2017-07-12 13:51 被阅读36次

    import scrapy
    from myproject.items import MyItem
    class MySpider(scrapy.Spider):
    name = 'myspider'
    start_urls = (
    'http://example.com/page1',
    'http://example.com/page2',
    )

    def parse(self, response):
        # collect `item_urls`
        for item_url in item_urls:
            yield scrapy.Request(item_url, self.parse_item)
    
    def parse_item(self, response):
        item = MyItem()
        # populate `item` fields
        # and extract item_details_url
        yield scrapy.Request(item_details_url, self.parse_details, meta={'item': item})
    
    def parse_details(self, response):
        item = response.meta['item']
        # populate more `item` fields
        return item
    
    59FC89FB-184B-4CCF-912E-1BD705D233DB.png

    相关文章

      网友评论

          本文标题:scrapy.Request 爬中爬

          本文链接:https://www.haomeiwen.com/subject/aarbhxtx.html