【问题标题】:Python requests How to get a page without downloading all images?Python请求如何在不下载所有图像的情况下获取页面?
【发布时间】:2016-11-03 05:06:04
【问题描述】:

我需要解析一个网页,它有很多图片,因此每个请求都需要很多时间。

我可以使用 requests.get 只获取 html 内容而不等待图像吗?

【问题讨论】:

    标签: python-3.x python-requests


    【解决方案1】:

    当您获取页面时,无论如何您只能下载页面本身。

    import requests
    
    url = 'https://stackoverflow.com/questions/40394209/python-requests-how-to-get-a-page-without-downloading-all-images'
    
    # This will yield only the HTML code
    response = requests.get(url)
    
    print(response.text)
    

    页面 HTML 包含对图像的引用,但 GET 请求不跟随它们。

    【讨论】:

    • 对不起,我很愚蠢,有时会问一些很愚蠢的问题。这只是 javascript 和地图加载。我会接受你的回答。难怪这个问题没有谷歌搜索结果。
    • 只是让你知道,你不是唯一一个认为图像也被下载的人,哈哈
    猜你喜欢
    • 2016-12-02
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-08
    相关资源
    最近更新 更多