import scrapy
from scrapy import Request
import json
from items import CsdnItem
class CSpider(scrapy.Spider):
    name = 'C'
    allowed_domains = ['blog.csdn.net']
    start_urls = ['https://blog.csdn.net/community/home-api/v1/get-fans-list?page=1&size=20&noMore=false&blogUsername=hihell']

    def parse(self, response):
        # 总页码临时设置为 10
        for page in range(2,11):
            print("正在爬取{}页".format(page),end="")
            yield Request("https://blog.csdn.net/community/home-api/v1/get-fans-list?page={}&size=20&noMore=false&blogUsername=hihell".format(str(page)), callback=self.parse_item)
    
    def parse_item(self,response):
        
        data = json.loads(response.body_as_unicode())
        print("*"*100)
        item  = CsdnItem()
        for one_item in data["data"]["list"]:  
            item["username"] =  one_item["username"]
            item["blogUrl"] =  one_item["blogUrl"]
            yield item