Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python requests How to get a page without downloading all images?

I need to parse a webpage and it has a lot of images, each request takes a lot of time because of it.

Can I use requests.get to get only html content without waiting for images?

like image 258
userqwerty1 Avatar asked Nov 03 '16 05:11

userqwerty1


1 Answers

When you GET a page, you only download the page itself anyway.

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)

The page HTML contains references to images, but the GET request does not follow them.

like image 194
Vasili Syrakis Avatar answered Oct 23 '22 22:10

Vasili Syrakis