A simple example of Python embedding is just written (almost enough for now ~), Next, let's look at the actual things. Without these applications, the previous embedding will be meaningless. When writing other embedded parts later, you don't have to understand all the functions at once, right ~
Okay. Let's see what I think is the most interesting part of the python library, that is, how Python operates web pages.
This article briefly explains how to download a webpage through a web site, on the premise of being able to access the Internet.
Here, I want to store the web pages under the test.html file.
Only two lines of code are required to download the webpage:
# Note that the current version of python3.1 has changed a lot. In the past, many codes were unavailable and need to be modified a little.
Import urllib. Request
Urllib. Request. urlretrieve ('HTTP: // www.163.com', 'test.html ') # How can I solve this problem if you use double quotation marks? Is there a difference between single quotes and double quotes?
Haha, I don't think it's too simple, but I still like the implementation of the code below (I didn't add an exception, if it's a bit formal code, add some code to handle exceptions ):
Import urllib
Import urllib. Request
Url = urllib. Request. urlopen ("http://www.163.com ")
File = open ("test.html", 'wb') # It's 'wb', not 'W'
While (1 ):
Line = URL. Readline ()
If Len (line) = 0:
Break
File. Write (line)
Oh, do you really feel boring about downloading a webpage ~
OK. Next I will explain how to parse the downloaded webpage so that the downloaded webpage will be useful ~ Pai_^