【问题标题】:Python3 Download Image from an WebpagePython3 从网页下载图像
【发布时间】:2020-06-10 17:07:20
【问题描述】:

我如何从这个 URL 下载图像:https://thispersondoesnotexist.com/ 我知道它没有一些图片网址,但我希望从那里得到一些图片。

我的想法是编写一个代码来从这个 URL 获取更多图像。

【问题讨论】:

    标签: html python-3.x image web-scraping download


    【解决方案1】:

    重复:Loop through webpages and download all images

    Python 2

    使用 urllib.urlretrieve

    import urllib
    urllib.urlretrieve("http://www.gunnerkrigg.com//comics/00000001.jpg", "00000001.jpg")
    

    Python 3

    使用 urllib.request.urlretrieve(Python 3 遗留接口的一部分,工作方式完全相同)

    import urllib.request
    urllib.request.urlretrieve("http://www.gunnerkrigg.com//comics/00000001.jpg", "00000001.jpg")
    

    【讨论】:

    • 当我使用这个例子时,我得到以下错误消息:“Forbidden” urllib.request.urlretrieve("thispersondoesnotexist.com ", "00000001.jpg")
    • 我的意思是当我将此代码用于此 URL 'thispersondoesnotexist.com
    猜你喜欢
    • 2019-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 2017-10-28
    • 2015-07-27
    • 1970-01-01
    相关资源
    最近更新 更多