Today, the project manager asked me a question, asked me here are 2000 URL to check whether it can be opened properly, in fact, I refused, I know because I have to write the code, it happens to learn a bit of Python, a thought, python deal with it easily, so I chose python, began to put the idea of good:
1. first 2000 URLs. can be placed in a txt text
2. Python puts the URLs in the content into an array one by one.
3. Open a simulated browser and visit it.
4. If the normal access to the output is normal, error output error
Straightforward, simple and brutal dumping of code. Images are coded because of the privacy implications
import import time opener = .build_opener() = [('User-agent', 'Mozilla/49.0.2')] #This is the name of the file where you put the URL, just change it. file = open('') lines = () aa=[] for line in lines: temp=('\n','') (temp) print(aa) print('Start checking:') for a in aa: tempUrl = a try : (tempUrl) print(tempUrl+'No problem') except : print(tempUrl+'=Error accessing page') (2) except : print(tempUrl+'=Error accessing page') (2) (0.1)
Rendering:
This is the whole content of this article.