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
 

猜你喜欢

转载自blog.csdn.net/qq_36958104/article/details/81482035
今日推荐