【发布时间】:2016-11-03 05:06:04
【问题描述】:
我需要解析一个网页,它有很多图片,因此每个请求都需要很多时间。
我可以使用 requests.get 只获取 html 内容而不等待图像吗?
【问题讨论】:
标签: python-3.x python-requests
我需要解析一个网页,它有很多图片,因此每个请求都需要很多时间。
我可以使用 requests.get 只获取 html 内容而不等待图像吗?
【问题讨论】:
标签: python-3.x python-requests
当您获取页面时,无论如何您只能下载页面本身。
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 请求不跟随它们。
【讨论】: