【问题标题】:How can I scrape a excel file from a website and divide it in different parts?如何从网站上抓取 excel 文件并将其分成不同的部分?
【发布时间】:2023-01-13 01:12:55
【问题描述】:

我需要创建一个解决方案,从确定大小的不同部分的网站上抓取 excel 文件。 每部分不能大于10MB,文件扩展名为(.xls)。

我能够写出确定大小的不同部分,但它们不能用于奇怪的字符。我试图改变编码,但它也不是......

代码示例:

with open(file, 'wb') as f:
        for part in requests.get(website_link, stream=True).iter_content(chunk_size=10000):
             f.write(chunk)
             actual_size += 10000
             if actual_size + 10000 >= maximum_chunk_size:
                break

【问题讨论】:

    标签: python excel web-scraping python-requests


    【解决方案1】:

    尝试使用Scrapy 或 beautifulsoup4 解析数据,比请求更方便。

    您可以像这样在运行时检查文件大小:

    import os
    
    file_name = "/path/to/file"
    
    file_stats = os.stat(file_name)
    size_mb = file_stats.st_size / (1024 * 1024)  # in megabytes
    size_kb = file_stats.st_size / 1024  # in kilobytes
    size = file_stats.st_size  # bytes
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多