广西互联网金融平台系列-Scrapy爬虫爬取泛湾天域数据

1、背景

与海金汇和小鹅网同样,泛湾天域也没有在技术上作防御,直接爬数据就能够了。这一波爬取广西网贷平台的数据,是想看看经过平台的数据,来推测或者估算平台的发展时期对应的运营行为。css

2、目的

抓取泛湾天域全站的标的数据和投资人记录数据dom

3、代码示例

这种网站,逻辑很是简单,进去 爬爬爬,完了。scrapy

class FanwantianyuSpider(scrapy.Spider):
    name = 'fanwantianyu'
    allowed_domains = ['www.fanwantianyu.com']
    start_urls = ['http://www.fanwantianyu.com/financing/sbtz/qylb/1']

    def parse(self, response):
        """
        将当前列表页的每条标的连接拿到
            并传给detail进行深刻爬取
            已知页码能够在url中循环  就不用翻页了
        """
        total = response.css('.w250 span.w200 a')
        for i in total:
            title_urls = i.css('::attr(href)').extract_first("")
            yield Request(url=parse.urljoin(response.url,title_urls),callback=self.parse_detail)
            pass

        for x in range(1,62):
            next_pages = "http://www.fanwantianyu.com/financing/sbtz/qylb/%s" % (x)
            yield Request(url=next_pages,callback=self.parse)

    def parse_detail(self, response):
        """  """
        f_loads = FanwanItemLoader(item=FanwanItem(), response=response)
        f_loads.add_css("title",".pub_title span::text")
        f_loads.add_value("target_urls", response.url)
        f_loads.add_value("target_urls_id", response.url)
        f_loads.add_css("amount", "div.ml30:nth-child(3) span:nth-child(2)::text")
        f_loads.add_css("profit", ".mr30 span.red.f24.mt10.mb10::text")
        f_loads.add_css("terms", ".mr30.ml30 span.f24.mt10.mb10::text")
        f_loads.add_css("protype", ".pub_title span::text")
        f_loads.add_css("status", ".plan_given_btn i::attr(class)")

        loaders = f_loads.load_item()
        yield loaders

        ilist_url = response.url.replace("bdxq","tbjl")
        yield Request(url=parse.urljoin(response.url,ilist_url),callback=self.parse_ilist)
        pass

    def parse_ilist(self, response):
        """ 投资记录 """
        total_tr = response.css('table.tc tr:not(:first-child)')
        for tr in total_tr:
            ilist_loader = FanwanListItemLoader(item=FanwanListItem(),response=response)
            ilist_loader.add_value("target_urls", response.url)
            ilist_loader.add_value("target_id", response.url)
            ilist_loader.add_value("invest_username",tr.css("td::text")[1].extract())
            ilist_loader.add_value("invest_amount", tr.css("td::text")[2].extract())
            ilist_loader.add_value("invest_time", tr.css("td::text")[3].extract())
            ilist_item = ilist_loader.load_item()
            yield ilist_item

4、有意思的数据

根据爬取的数据,作了个基础的总结,发现了几个有意思的数据ide

1.泛湾天域这几年总共发了610个标,其中金额最大的是2017-01-19那天发出的,用于补充借款人企业流动资金的标的,金额是300万,收益率也还能够,15%。网站

2.最小金额的借款是借了3万元url

3.总投资笔数为10015条(截止数据抓取日期),这样算下来,平均每一个标的产生的投资笔数为16.4次。spa

4.单笔投资金额最大的用户是[Quee***],所投资的金额为100万,也就是上面的那个300万借款的那条。这个用户的投资笔数很少,就5笔,[2.5万,100万,20万,20万,11万]code

5.泛湾天域最先的一笔投资是发生在2015-05-28,那个美好的傍晚[W818***]投了第一笔1.3万元的投资,开启了泛湾天域的征途(第二笔也是他,7千,两次投资相隔1分钟)。这位用户厉害了,总共在泛湾天域投资了227笔。最高单笔投资27万、最低也有投100的时候(估计是自动投标或者参与平台活动)ci

相关文章
相关标签/搜索