First of all, even if there is nothing, I will fetch the main body. Currently (December 2014), python has both 2.x and 3.x series. This time, I will use 2.x series, which has a lot of documentation, especially version 2.7, which is the mainstream.
Well, it was a PC a long time ago, so download the installer for 32bit from python head family.
Launch the downloaded installer and press OK at will to complete the installation of python itself.
I've installed python, but I need to make sure the system can find it. Add the location of the python installed this time (C: \ python27) to the location where the system searches for the execution command (environment variable called Path).
First, open the screen where you can edit the environment variables.
Control> System-> Advanced System Settings-> Environment Variables
Looking at the system environment variables in the screen that appears, I think there is a variable Path. Select it and press the edit button.
Add the following to the variable value of the screen that appears (backslash is a yen mark)
C:\Python27;C:\Python27\Scripts;(Existing)
After writing, press OK to close some open windows.
Menu-> Accessories> Command Prompt
From, open the terminal,
python --version
Hit. If the version information such as "Python 2.7.9" is returned, it is successful.
<!-With ez_setup
python ez_setup.py
-->
To develop with python, you have to insuko various packages (libraries (collections of utilities created by others)) and use them.
If a certain package is created on the premise of a certain package, the original package must also be installed ... What? If you go with this version, it will take many days just to insuko.
The package management tool solves this problem all at once. Among them, this time we will put pip (Python Package Installer) recommended by python. The procedure is simple.
easy_install pip
It will be inscored just by (I put a path to Scripts with the above Path setting, but easy_install is included there).
To insuko using pip, you can insuko by doing the following. As a test, let's insuko ipython.
pip search ipython
When you see the package you want, let's go next.
pip install ipython
only this.
Insuko Beautiful Soup before testing. This is a library that structures HTML code so that it is easy to handle programmatically.
pip install BeautifulSoup
Any text editor is fine, but since it's a big deal, I'll introduce the oython editor for beginners.
Go to the PyScripter page and download the file PyScripter-v *. *. *-Setup.exe
in Featured. ,I will do it. (If you are using a 64-bit machine, please select the file that says x64.)
Follow the installer's instructions faithfully and let's OK like a tuna. It is convenient to start it if you generate an icon on the desktop.
Start pyscripter and write the following code.
import urllib2 # get request from url via the internet.
from BeautifulSoup import BeautifulSoup # html parser
def getTitle(url):
# get the server response
res = urllib2.urlopen(url)
# load html code
html = res.read()
# analyse html code
bs = BeautifulSoup(html)
# extract the text of title
return bs.title.text
def main():
url = "http://docs.python.jp/2.7/tutorial/index.html"
title = getTitle(url)
print title
if __name__ == '__main__':
main()
Save it to a suitable location with Ctrl-s (I save it under C: / Users / myname / develop /) and execute it with Ctrl-F9.
It's nothing but code that shows the title of the url in the source, but it's the basis of HTML parsing.
···to be continued.
Recommended Posts