1. 程式人生 > >python 爬蟲爬去自己部落格的訪問量

python 爬蟲爬去自己部落格的訪問量

廢話不多說,我也是剛剛學習小白一個,但是經過我的測試確實是可以用的,只不過大家要把時間設定的要長一點

 

先上程式碼,使用py3    程式碼的相關解析可以看我的其他部落格,裡面有詳細的介紹

 


__author__ = 'MrChen'
 
import urllib.request
import time
 
#使用build_opener()是為了讓python程式模仿瀏覽器進行訪問
opener = urllib.request.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
 
#專刷某個頁面
print('開始:')
tempUrl = 'https://blog.csdn.net/qq_36958104/article/details/81478364'
tempUrl1 = 'https://blog.csdn.net/qq_36958104/article/details/81298356'
tempUrl2 = 'https://blog.csdn.net/qq_36958104/article/details/81336086'
tempUrl3 = 'https://blog.csdn.net/qq_36958104/article/details/81477140'
for j in range(20000):
    try :
        opener.open(tempUrl)
        opener.open(tempUrl1)
        opener.open(tempUrl2)
        opener.open(tempUrl3)
        print('%d %s' % (j , tempUrl))
        print('%d %s' % (j , tempUrl1))
        print('%d %s' % (j , tempUrl2))
        print('%d %s' % (j , tempUrl3))        
    except urllib.error.HTTPError:
        print('urllib.error.HTTPError')
        time.sleep(60)
    except urllib.error.URLError:
        print('urllib.error.URLError')
        time.sleep(60)
    time.sleep(60)
 

 

而且我還刷了我的爾雅課的訪問量。

 

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 

================= RESTART: C:/Users/wei/Desktop/paqucsdn.py =================
0 https://blog.csdn.net/qq_36958104/article/details/81478364
0 https://blog.csdn.net/qq_36958104/article/details/81298356
0 https://blog.csdn.net/qq_36958104/article/details/81336086
0 https://blog.csdn.net/qq_36958104/article/details/81477140
1 https://blog.csdn.net/qq_36958104/article/details/81478364
1 https://blog.csdn.net/qq_36958104/article/details/81298356
1 https://blog.csdn.net/qq_36958104/article/details/81336086
1 https://blog.csdn.net/qq_36958104/article/details/81477140
2 https://blog.csdn.net/qq_36958104/article/details/81478364
2 https://blog.csdn.net/qq_36958104/article/details/81298356
2 https://blog.csdn.net/qq_36958104/article/details/81336086
2 https://blog.csdn.net/qq_36958104/article/details/81477140
3 https://blog.csdn.net/qq_36958104/article/details/81478364
3 https://blog.csdn.net/qq_36958104/article/details/81298356
3 https://blog.csdn.net/qq_36958104/article/details/81336086
3 https://blog.csdn.net/qq_36958104/article/details/81477140
4 https://blog.csdn.net/qq_36958104/article/details/81478364
4 https://blog.csdn.net/qq_36958104/article/details/81298356
4 https://blog.csdn.net/qq_36958104/article/details/81336086
4 https://blog.csdn.net/qq_36958104/article/details/81477140