【问题标题】:Python: Download and save PDF from websitePython:从网站下载并保存 PDF
【发布时间】:2021-09-17 15:45:55
【问题描述】:

我正在尝试按照此脚本从网站下载 pdf 文件。

import requests

url = 'http://www.adassothai.com/include/upload/images/th_exp_file/2018011210091045062.pdf'
r = requests.get(url, allow_redirects=True)
file = open(url, 'wb').write(r.content)

我发现了错误

OSError: [Errno 22] Invalid argument: 'http://www.adassothai.com/include/upload/images/th_exp_file/2018011210091045062.pdf'

我正在寻找一些想法来解决这个问题。 提前谢谢你。

【问题讨论】:

    标签: python web-scraping error-handling python-requests downloadfile


    【解决方案1】:

    试试这个:

    from pathlib import Path
    import requests
    filename = Path('metadata.pdf')
    url = 'http://www.adassothai.com/include/upload/images/th_exp_file/2018011210091045062.pdf'
    response = requests.get(url)
    filename.write_bytes(response.content)
    
    Source: https://stackoverflow.com/questions/34503412/download-and-save-pdf-file-with-python-requests-module
    

    【讨论】:

      猜你喜欢
      • 2022-09-25
      • 2020-10-10
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2013-05-18
      • 1970-01-01
      • 2016-01-03
      • 2019-07-04
      相关资源
      最近更新 更多