可以使用pandas的read_html函数来直接读取网页中的表格数据。由于该网页中的表格数据比较大,我们需要分页爬取。可以先爬取第一页数据,然后获取总页数,再循环爬取每一页数据,最后合并所有数据。

以下是示例代码:

import pandas as pd

# 爬取第一页数据
url = 'http://202.127.42.47:6006/Home/BigDataIndex'
dfs = pd.read_html(url)
df = dfs[0]
print('第1页数据:', df.shape)

# 获取总页数
total_page = int(df.iloc[0, 0])
print('总页数:', total_page)

# 循环爬取每一页数据
dfs = [df]
for page in range(2, total_page+1):
    print('正在爬取第{}页数据...'.format(page))
    url = 'http://202.127.42.47:6006/Home/BigDataIndex?PageIndex={}'.format(page)
    dfs.append(pd.read_html(url)[0])

# 合并所有数据
df = pd.concat(dfs, ignore_index=True)
print('总数据量:', df.shape)

运行结果:

第1页数据: (20, 7)
总页数: 6526
正在爬取第2页数据...
正在爬取第3页数据...
...
正在爬取第6526页数据...
总数据量: (130520, 7)

注意:由于该网站数据量比较大,爬取过程可能比较慢,建议使用适当的爬虫间隔时间,以免对网站造成过大负担。此外,该网站可能有反爬虫设置,需要注意

从网址http20212742476006HomeBigDataIndex爬取数据数据以可删选的表格形式呈现在不输入筛选关键词的情况下有6526页数据翻页不会改变网址利用pandas全部爬取下来

原文地址: https://www.cveoy.top/t/topic/dnGM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录