In Python 3.7/Django 3, how can I get the rendered HTML of a page in a web browser?

I’m using Python 3.7 with Django 3. I currently use the following code for generating a web browser with a given URL

filePath = '/tmp/cat_and_dog.webp' searchUrl = 'http://www.google.hr/searchbyimage/upload' multipart = {'encoded_image': (filePath, open(filePath, 'rb')), 'image_content': '', } response = requests.post(searchUrl, files=multipart, allow_redirects=False) fetchUrl = response.headers['Location'] webbrowser.open(fetchUrl) 

How do I get the HTMl of the rendered DOM? Note that this is different than what "view source" reveals. I’m more interested in getting a version of the DOM that I see when I run "Inspect Element" in my browser. I may be using improper terminology but hopefully it is clear the actual HTML I wish to extract what the browser renders.

Add Comment
1 Answer(s)

maybe you can use the render_to_string function

from django.template.loader import render_to_string  def some_function():      rendered_template = render_to_string('template_name.html','context') 
Answered on July 16, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.