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

利用python bs4爬取企业逾期数据

程序员文章站 2022-05-04 16:52:53
...

'''
参考文档: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

url='http://www.hnxcdb.com/readgg.asp?id=1623'
html=requests.get(url)
html.encoding='gb2312'   # 查看网页编码
html=html.text
content=BeautifulSoup(html,'html.parser').tbody  # 定位tag

res=[]
for ele in content.find_all('tr'):
    a=[]
    for ele1 in ele.find_all('td'):
        if not ele1.string is None:
            a.append(ele1.string.strip())
    print(a)
    temp=','.join(a)
    res.append(temp)

 

相关标签: python bs