Installation and use of Python under Windows

Source: Internet
Author: User

Main content:

1. Installation of Python

2. A few small examples of Python crawlers

--------------------------------------------------------------------------------------------------------------- ------------------------------------

1. Installation of Python

Under Windows is generally used Jdk+eclipse+python installation, where Eclipse is an editor, write code, embed python into the eclipse environment, Implement code that has a. py extension under Eclipse, and then call the Python program directly to parse it. As for the JDK, it is inseparable from eclipse as a good base friend. Installation should be noted that the operating system is 32-bit or 64-bit, according to select the appropriate installation version, my is a 32-bit system, The JDK version used is the Jdk-8u112-windows-i586.exe,eclipse version is the Eclipse-jee-neon-1a-win32.zip,python version of Python-2.7.12.msi, the specific installation method see: HTTP ://www.cnblogs.com/realh/archive/2010/10/04/1841907.html.

2. A few small examples of Python crawlers

(1) A small example of http://www.cnblogs.com/Bonker/p/3584707.html is implemented.

1Name =raw_input ('What is your name?')2 ifName.endswith ('Tank'):3Print'Hello Tank'4Elif Name.endswith ('Xiao'):5Print'Hello Xiao'6 Else:7Print'Hello Strange'  

To explain, the first line creates the name object, which, through the python built-in function raw_input, interacts with the user by reading the console input, and the runtime prompts the console to "What's your name?" and the user needs to enter character information after that;

Line 2nd to 7th, is a multi-branch selection structure, judging by the name of the EndsWith method of the object, the EndsWith () method is used to determine whether the string ends with the specified suffix, if the end of the specified suffix returns true, otherwise return false, run the result is as follows:

(2) A small example of reading Baidu Web page information

1#coding: utf-82 " "3 Created on December 20, 20164 5 @author: Adminstrator6 " "7 Import Urllib28 " "9 The requested address creates a request object,Ten by calling Urlopen and passing in the request object, a related request response object is returned . One  A " " -req = Urllib2. Request ('http://www.baidu.com')     -Response =Urllib2.urlopen (req) the #Response中调用. Read () -The_page =Response.read () -     -Print The_page

#coding: Utf-8 in the py file to write Chinese, you need to add such a line to declare the file encoding comments, otherwise python2 will default to use ASCII encoding;

Lines 2nd and 6th represent the comments between the two lines, and the lines 8th and 12th are the same.

About URLLIB2, this blog explains very clearly: http://www.360doc.com/content/13/0204/13/3046928_264179264.shtml, the program also has comments, Call the Urlopen function to return a Respons object to the requested URL, the respons is a class file object, so we can use the Read () function to manipulate the Respons object. The execution effect is as follows:

Installation and use of Python under Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.