I decided to take my spare time to learn Python in the first half of the year. I printed out the "A Byte of Python" online one week before and read an article about the basic knowledge of Python syntax.
Show a python script to access Netease's blog. This is a prototype that was found online for fun last year. I can work on python2.6 last year. Now I am learning python3, so the following is the python3 Code. In addition, the company's network must be configured with a proxy to access the Internet, so the proxy settings are added.
BTW, after testing, this script can be used as the top sticker of Netease blog. It seems that NetEase blog does not perform deduplication or other processing on multiple access records of the same IP address. Of course, in addition to simple tests, I didn't use such a program to record my blog. I don't think it's interesting. In the code, the visitTimesPerPage variable sets the number of visits to each url. If it is set to 1000, each url will be accessed 1000 times.
The Code is as follows:
#! /Usr/bin/python3 #-*-coding: UTF-8 -*-
"'Created on @ author: laugh all over the world "'
Import sysimport threadingimport urllib. request
Urls = ["blog/static/16005312010101782448207/", "blog/static/16005312010111233057624/", "blog/static/16005312010111244548449/",]
VisitTimesPerPage = 10
Def usage (): print ('usage: ', sys. argv [0], 'host ')
Def main (argv): host = argv [1] if host = ": usage () sys. exit (2) else: for I in range (visitTimesPerPage): for url in urls: visitPageThread = VisitPageThread (url + str (I), host, url) visitPageThread. start ()
Class VisitPageThread (threading. thread): def _ init _ (self, threadName, host, url): threading. thread. _ init _ (self, name = threadName) self. host = host self. url = url def run (self): url = self. host + self. url req = urllib. request. request (url) req. set_proxy ('companyname. com: 911 ', 'http ')
# You may set you proxy here.
Try: doc = urllib. request. urlopen (req). read () print (doc) failed t Exception as e: print ("urlopen Exception: % s" % e)
If _ name __= = '_ main _': sys. argv. append ('HTTP: // ren ** .blog.163.com/') main (sys. argv)
This is my first python script. mark it !~