Python - Get Page Source from URL

Here I am giving an example of a Python program to get page source from the URL.

You will get the same web page source as you used to view by doing the right-click on the web page and then select the option View Page Source as shown in the image above. Below is an example:

Python Program to Get Web Page Source

import requests


r = requests.get(v_url)

page_source = r.content


Output (Displaying few lines from actual production)

<!doctype html>
<!--[if lt IE 7]>   <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9">   <![endif]-->
<!--[if IE 7]>      <html class="no-js ie7 lt-ie8 lt-ie9">          <![endif]-->
<!--[if IE 8]>      <html class="no-js ie8 lt-ie9">                 <![endif]-->
<!--[if gt IE 8]><!--><html class="no-js" lang="en" dir="ltr">  <!--<![endif]-->

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <link rel="prefetch" href="//">

See also:

Leave a Comment