Write a python, crawl [you star sky] wallpaper (2)

Abstract of the previous article/Content of this article:

In the last article, we have already installed some software. Although the sharpening of the knife is not mistaken for the woodworking, but the sharpening of the knife is also skillful.

Isn’t it necessary to debug after python is installed?

Don't you think the font is very small after pycharm is installed?

Could it be that you can understand so much English?

If you have no such distracting thoughts in your mind, and all the codes are just 26 letters with a few broken characters in your eyes, then you are the old driver in our minds, take me to the start!


Python third-party libraries:

The power of python is that it has a very powerful third-party library. The so-called third-party library means that you want to implement a certain function, but you can't write it. At this time, someone wrote it out and packaged it into a module. You only need to import this module, follow its instructions, call its methods, and you can achieve the functions you want!

It is said that it is a third-party library, not python's own, you need to install it, here is definitely an easy installation [pip]

grammar:

pip install XXXXXX

XXXXX is the name of the module you want to install, for example, if I want to install the [requests] library, execute [pip install requests]


Before installing the third-party library, if import is introduced, python will report an error, the error type is [ImportError], this kind of error is easy to solve, as long as it is not a particularly exotic library, you can install it with pip


pip debugging:

The installation of pip is actually downloading third-party libraries from its server to the local. The problem now is this, its server is outside the wall, and you, inside the wall, even if only a few MB in size You may have to wait for a long time

This thing is the same as the source of Linux. If you want to enjoy the speed of light download in the world inside the wall, you can change the source. Here, we choose the pip source of Tsinghua University, which is a mirror image of the pip official website, every 5 Synchronize every minute, the address is https://pypi.tuna.tsinghua.edu.cn/simple

If you use it temporarily, add the parameter [-i] during pip. For example, if you install the requests library, temporarily use the source of Tsinghua University

【pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple】




If you want to use the source of Tsinghua University once and for all, you only need to modify the configuration file

Modify the configuration file under Windows:

Create a pip folder in the user directory


Create a new pip.ini file with the following content

[global]

index-url = https://pypi.tuna.tsinghua.edu.cn/simple



Modify the configuration file under Linux:

Modify ~/.pip/pip.conf (create one if not), the content is the same


In this way, you can enjoy the speed of light network inside the wall



pycharm debugging:

To be honest, the default font of pycharm is really small, and I like the black theme of sublime, and the code is colorful, which is very high at first glance, so this thing must be adjusted!

We first define a few blocks



在File -> Settings -> Editor -> Colors & Fonts




Adjust a color scheme, I like to use [Monokai]



A prompt popped up, which probably means that I prefer dark-toned themes. Do you want to configure pycharm as a dark-toned theme? For such a friendly function, of course, I choose Yes.



Then change the font style, adjust the font size, I changed to [Source Code Pro] font, and the Size to 20



emmm, it’s obviously bigger, and it’s more comfortable to look at



There is a situation: If my python statement is very long and I want it to wrap automatically, then I have to activate this function

view -> Active Editor -> Use Soft Wraps



If you want to achieve the same function on the console, just click the word wrap here, you can



This is the rendering



I also hope to realize this function, that is, every time I generate a new python file, I will put relevant comments at the beginning, for example, some specified encoding types, file creation time, file The creator of pycharm, etc., in fact, pycharm can achieve this function

在File -> Settings -> Editor -> File and Code Templates -> Python Script

What do you want at the beginning, just type it up, how about it, isn’t it very convenient?




end:

At this point, python's pip debugging and pycharm debugging have come to an end. Next, you can officially start writing the crawling script

Guess you like

Origin blog.csdn.net/cbcrzcbc/article/details/79328802