0

I'm looking to request a webpage with python and to get the source code to string (my page has only text for exmaple Year2012 with no html or other codes so if you do view source you see Year2012 this is what I need)

for example I have this C# code what I want in Python:

string WebClient = new WebClient().DownloadString(WebPage);

If I create myscript.php and enter Year2012 string WebClient will be = "Year2012" If I change it later on and my program check the webpage it will be what ever I change. I want the same thing In python for windows any idea how?

Thanks!

Mark
  • 475
  • 2
  • 8
  • 18

1 Answers1

3

I suggest you using the package requests.Here is a code snipet that may meet your need:

import requests
r = requests.get('https://github.com/timeline.json')

EDIT:

Or you may use the default package in python: urllib2, a simple example:

import urllib2
f = urllib2.urlopen('http://www.python.org/')
print f.read(100)

The output:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?xml-stylesheet href="./css/ht2html
prehistoricpenguin
  • 3,842
  • 1
  • 21
  • 34