Recently, I used python to write crawlers. I started to use 3.4, but it was hard to write them. However, I often stopped working at runtime. After I reduced the number of threads (16-& gt; 8, stability has been improved, but there are still occasional problems of stopping work. Therefore, I changed python3.5 and found that some packages do not support 3.5. So I listened to the suggestion and changed to the most popular version 2.7. As a result, the sqlite3 package reported an error for no reason. DatabaseError: malformeddatabaseschema, after the number of threads is reduced (16-> 8), the stability is improved, but there is still the problem of stopping work occasionally. Therefore, I changed python3.5 and found that some packages do not support 3.5. So I listened to the suggestion and changed to the most popular version 2.7. As a result, the sqlite3 package reported an error for no reason.
DatabaseError: malformed database schema (is_transient)-near "where": syntax error
This error is reported if the SQL statement does not have a where clause, and the original program can run successfully in python3.4. Of course, I have changed the 3to2 difference.
Finally, before giving up python, I would like to ask you where are the advantages of python? I personally feel that the language itself is somewhat unstable and sometimes some inexplicable errors may occur. This is my problem or python. Reply: I personally think that problems encountered in python development may also occur in other languages. The process of solving these problems is to deepen your understanding of some aspects.
The problem was not found. The python version was changed back and forth, but the python version was quite different. We recommend that you search for more error information to understand the problem.
The advantages of python are as follows: simple and clear, easy to use, and have a lot of resources. I guess the web page you crawled contains where, and you wrote it to SQL. As a result, your statement contains where.
This is generally your own problem. I think it is a question of programming philosophy.
In most cases, programming is designed to solve the problem. Programming for the sake of high technology is actually very rare.
Take crawlers as an example.
Crawling and data profiling are usually a small part of the entire big problem (generally the first step ), the collected data is used for analysis, filtering, or posting robots, even if it is just a simple batch download of Sister pictures. The main focus of the entire task and the environment that "generates benefits" are subsequent. Naturally, writing crawlers is how fast and how energy can be saved.
In most cases, Py is the best choice for doing this (at least for the first time ). You don't need to think about all the compiled languages. To be precise, you can ignore languages that do not provide interactive environments, and the debugging cost is too high. So what else is there? Python, Nodejs, and Ruby.
Nodejs is designed to be asynchronous, and asynchronous is a bit redundant for programs such as crawlers.
Ruby is actually a good choice, but it has some inherent defects. Its syntax is too "exquisite". When you use it, I often fall into the trap of "more elegant I can do", but this elegance does not bring you any benefit, the business logic of your next crawler is similar to that of your crawler. It's hard for you to be elegant and elegant everywhere. Unless you write Ruby in your main business (not counting ROR), you will easily fall into a difficult choice.
In contrast, Python is simple, crude, and has no brain stem. Simple enough syntax allows you to focus on:
" "
How does the opposite server return?"
" "
Why does it block Lao Tzu?"
" "
You cannot load the data all at once."
" "
How can you pass the parameters of your js function to sign2 and then to sign1!"[Real story: function (sign2, sign1) when a famous online disk signature function is calculated, so I got stuck for two hours]
" "
Guy, your page structure is too messy."
" "
Haha, 502 error"
" "
I am a genius"
These important issues.
When you have these similar experiences, you find that some things are similar. You started to access some crawler frameworks and accumulated some handy libraries, extracted some reusable code, and started to have a broader idea. You find that if you can directly use JS on the target website, it would be nice to start running js in Py. Why don't I call wget directly? The boss said, "You gave me an application with an interface." You found that using py2exe to package command lines, c # + wpf to drag a form program is not that troublesome.
At this time, you will have a sigh of "Python is really good". After drinking tea, you will have finished writing the program. (What, performance? Otherwise, why do you think you want to drink tea? Wait. I cannot upgrade the configuration)
[End] I can't cook delicious meals. Is it a problem with kitchenware? 「 Work is usually stopped during running. After the number of threads is reduced (16-> 8), the stability is improved, but there is still a problem of stopping work occasionally 」
Obviously, this is because you do not understand multi-threaded programming and do not apply lock protection to relevant data. If your logic is complex, it is very difficult to debug it later.
If you do not know
Consider the existence of another thread at all timesTo make necessary data
Lock ProtectionWe recommend that you do not use multiple threads. (If you must use multiple threads, you can only use Rust-there, multi-threaded programs that do not properly protect data can not be compiled .)
I have written a multi-threaded crawler, and I have never used a multi-threaded crawler again. Too much effort.
In addition, remember that Python 3.x and 2.x are similar.
Two different languages, It is normal for a good program to change to another one. 3to2 and 2to3 are only auxiliary tools and cannot completely solve the problem (or they do not need to be incompatible ). Let's talk about it at 1.1:
It is hard to finish writing, but the work is often stopped during running. After the number of threads is reduced (16-> 8), the stability is improved, but there is still the problem of stopping work occasionally.
First, crawlers are IO-intensive programs (network I/O and disk I/O). Most of the bottlenecks of such programs are network and disk read/write speeds, and Multithreading
To some extentIt can accelerate the crawler efficiency, but this "Acceleration" cannot exceed min (outbound bandwidth, disk write speed). Moreover, due to the existence of GIL, in fact, there are some pitfalls that cannot be easily discovered by beginners.
Some packages do not support 3.5
The split between Python2 and 3 is indeed quite brainless, but as far as I know, most Python crawler-related libraries already support Python3.x, And I Don't Know What library is used by the subject. Of course, I prefer to use Python2.7.x ~~~
Therefore, follow the suggestions and change to the most popular version 2.7. As a result, the sqlite3 Package reports an error for no reason.
DatabaseError: malformed database schema (is_transient)-near "where": syntax error
This error is reported if the SQL statement does not have a where clause, and the original program can run successfully in python3.4. Of course, I have changed the 3to2 difference.
The large "syntax error" already tells you that your SQL statement has an error ~ However, considering the diversity of crawler data, we recommend that you use a NoSQL database. If you are not currently confused about the database selection, we recommend that you start with MongoDB.
Finally, before giving up python, I would like to ask you where are the advantages of python? I personally feel that the language itself is somewhat unstable and sometimes some inexplicable errors may occur. This is my problem or python.
Here, the first suggestion is to write "python" as "Python". This is
Rigorous attitude of a software engineer. Second, Python does not dare to say it is perfect, but the answer to the phrase "is my question or a python question" should be the question of the subject, if it takes a beginner three minutes to pick out a fatal Bug, it will never have the current market.
In fact, Python itself is very simple, although there are some "advanced" usage, but even if not, you can quickly write practical code. Programming design is more than programming languages, network protocols, design patterns, mathematics, algorithms, and so on. These are the knowledge that spans programming languages but programming will use, it is also the difference between high-quality code and low-level code. It's very responsible to say it's your problem ...... Because the masses of the people who have been honed to write crawlers under the combination of modules and frameworks have no problems, you can only show that you have a large understanding of crawlers or one of python..
The advantage is actually simple and easy to grasp. As long as you understand coding, http, html, and js, you can understand a little about the database. If you want to write a database, you can also use orm to directly operate the database, there is no need to recreate all kinds of ready-made wheels, and there is no need to worry about the details of all kinds of frameworks ......
Is there a more convenient choice? Yes. Currently, it is easier to use node to write data ...... Of course, there are more pitfalls. If you can, go to the code! Talk is cheap, show me the code why the subject does not study why he stops working but changes the version? Python is not windows → _ →