Python (programming language)/GetURL.py: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Eric M Gearhart
No edit summary
imported>Daniel Mietchen
m (typo)
Line 12: Line 12:




You can try this from home! Paste this script into a file (such as getimg.py) and if you have installed a Python interpreter you can run this script. On Mac OS or Linux you probably have Python already, those on Windows you will have to install Python (from http://python.org)
You can try this from home! Paste this script into a file (such as getimg.py) and if you have installed a Python interpreter you can run this script. On Mac OS or Linux you probably have Python already, those on Windows will have to install Python (from http://python.org)

Revision as of 07:38, 29 June 2009

This article is developing and not approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
 
Template:GetURL.py header

This script is a simple example of Python's urllib2 built-in function, and illustrates how easy it is to use network functionality directly in Python

import urllib2
cnt=0
for line in urllib2.urlopen('http://en.citizendium.org/wiki/Main_Page'):
    cnt += line.count('<img src')
print cnt


You can try this from home! Paste this script into a file (such as getimg.py) and if you have installed a Python interpreter you can run this script. On Mac OS or Linux you probably have Python already, those on Windows will have to install Python (from http://python.org)