Python (programming language)/GetURL.py: Difference between revisions
Jump to navigation
Jump to search
imported>Eric M Gearhart No edit summary |
imported>Tom Morris m (Python programming language/GetURL.py moved to Python (programming language)/GetURL.py: Python is not called "Python programming language". It is called "Python" and it is a programming language.) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{subpages}} | {{subpages}} | ||
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 | |||
<pre> | <pre> | ||
import urllib2 | import urllib2 | ||
cnt=0 | cnt=0 | ||
for line in urllib2.urlopen('http://en.citizendium.org/wiki/Main_Page'): | for line in urllib2.urlopen('http://en.citizendium.org/wiki/Main_Page'): | ||
Line 9: | Line 11: | ||
</pre> | </pre> | ||
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 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 (Python is free, [[open source]] software - no charge for downloading or using it) |
Latest revision as of 06:04, 8 August 2009
![](http://s9.addthis.com/button1-share.gif)
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 (Python is free, open source software - no charge for downloading or using it)