欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

利用python bs4爬取个人逾期数据

程序员文章站 2022-05-04 16:49:47
...


'''
参考文档:http://docs.python-requests.org/zh_CN/latest/user/quickstart.html  requests

https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html bs4

'''

# -*- coding: UTF-8 -*-

from bs4 import BeautifulSoup
import  requests
result=[]
for x in range(1,35):
    url="https://www.kaopuniao.com/user/info/list/exposure"
    data={
        'pageNumber': x,
        'pageSize': 10,
    'sortColumns': '',
    'search': 'search'
    }

    html=requests.post(url,data=data).text
    content=BeautifulSoup(html,'html.parser')
    if content.table['class'][0]=='gridtable':
        html1=content.table.tr
        #for ele in html1.find_all('th'):
           #print(ele.string)
        html2=content.table.tbody
        res=[]
        for ele in html2.find_all('tr'):
            a=[]
            for ele1 in ele.find_all('td'):
                if not ele1.string is None:
                    a.append(ele1.string.strip())
            temp=",".join(a)
            res.append(temp)
    result.extend(res)


print(len(result))