Menu Close

How to get html code from console of a website

To retrieve the HTML code of a webpage from the browser console, you can use the document.documentElement.outerHTML property. This property returns the full HTML code of the current webpage, including the <html> and <body> elements, as a string.

To access the HTML code of a webpage from the browser console, follow these steps:

  1. Open the webpage that you want to retrieve the HTML code of in your web browser.
  2. Open the browser console by pressing the F12 key on your keyboard (or by using the “Developer Tools” option in the browser’s menu).
  3. In the console, enter the following code:
document.documentElement.outerHTML
  1. Press the Enter key to execute the code. The HTML code of the webpage will be displayed in the console.

You can then copy the HTML code from the console and paste it into a text editor or other application to save it or use it for other purposes. Note that the HTML code displayed in the console may be truncated if it is very long, in which case you can use the console.log function to print the entire HTML code to the console. For example:

console.log(document.documentElement.outerHTML);

This code will print the full HTML code of the webpage to the console, which you can then scroll through and copy as needed.

Leave a Reply

Your email address will not be published. Required fields are marked *