Society & Culture & Entertainment Literature & Language

How to Read From a Website With Python

    • 1). Import the "urllib2" library:

      >>>import urllib2

    • 2). Request data from a URL through the "urlopen" function:

      >>>info = urllib2.urlopen('http://www.google.com')

    • 3). Print the data in the variable. The variable will contain the source code for the webpage:

      >>>print info.read(89) //reads 89 characters from the source file
      html><html><head><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">

You might also like on "Society & Culture & Entertainment"

Leave a reply