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:
- Open the webpage that you want to retrieve the HTML code of in your web browser.
- Open the browser console by pressing the F12 key on your keyboard (or by using the “Developer Tools” option in the browser’s menu).
- In the console, enter the following code:
document.documentElement.outerHTML
- 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.