zoukankan      html  css  js  c++  java
  • 测试博客园的阅读量计算方式

    内容:通过wget批量下载我自己博客园的随笔页面,看阅读量是否增加
    环境:kali+python
    思路:1、在终端利用调用脚本的方式执行python脚本,比如:python add_readcounts.py -f my_blogs
    2、对爬虫不熟,但是也不能把每一篇随笔的链接加入到代码中,使用一个文本保存,获取一个file变量
    3、通过python执行系统命令

     1 import optparse
     2 
     3 #get the file that user input, return the open file,通过终端输入拿到文件名称并且打开,返回一个file变量
     4 def get_file():
     5     parser = optparse.OptionParser("usage %prog"+"-f <link_file>") # 运行脚本的格式
     6     parser.add_option('-f', dest = 'fname',type = 'string', help = 'specify link file')   # 添加运行脚本的变量
     7     (options, args) = parser.parse_args()  # 把终端获取的变量进行保存,这里不知道怎么解释,有点要意会
     8     if options.fname == None:    # 文件位置参数不正确,输出使用方法,程序结束
     9         print parser.usage
    10     file_name = options.fname
    11     #file_name = 'test'
    12     f = open(file_name,'r')
    13     return f
    14 
    15 # execute the shell commands 执行命令,我测试了几种方法
    16 #import subprocess
    17 import commands,os
    18 def execute_shell(s):
    19     #obj = subprocess.Popen('wget',shell=True,stdout=subprocess.PIPE)
    20     #x = obj.stdout.read()       这是第一种方法,有点问题,因为不熟悉就没有使用
    21     shell_command = ' '.join(['wget','-O','x',s])    # 因为wget是下载网页,所以我把每次的结果都写到一个文件里面,这样不会生成很多网页
    22     #print(shell_command)
    23     os.system(shell_command)          # 通过系统执行命令
    24     #print(commands.getstatusoutput(shell_command))
    25     #(status, result) = commands.getstatusoutput(shell_command) # 这种方法会阻塞,所以也不使用
    26     #print(result)  
    27     
    28 
    29 
    30 import re
    31 if __name__ == '__main__':
    32     f = get_file()
    33     run_num = 0
    34     for s in f:
    35         #s = re.sub(';','',s)
    36         #print(s)
    37         execute_shell(s)
    38         run_num += 1
    39     
    40     print 'the website is :',run_num
    View Code

    忘记放我的文本文件上来了,现在补上

    文件名:my_blogs

    内容

    http://www.cnblogs.com/-nbloser/p/7854170.html
    http://www.cnblogs.com/-nbloser/p/7873562.html
    http://www.cnblogs.com/-nbloser/p/7901274.html
    http://www.cnblogs.com/-nbloser/p/7901295.html
    http://www.cnblogs.com/-nbloser/p/7979969.html

    。。。。。。

    我多次运行过后发现,我win10点击+虚拟机点击都会增加1,再次点击不会出现增加的数量,可能是记录电脑的某个信息。所以这种刷的方式可能不是很实用。不过写这个程序倒是蛮有意思的。

  • 相关阅读:
    怎样跟踪来访用户?
    五个瓶颈影响你的Asp.Net程序(网站)性能
    if判断与比较操作符gt、lt、eq等的使用
    裸机LCD驱动配置
    汇编指令-位置无关码(BL)与绝对位置码(LDR)(2)
    汇编指令-MRS(读)和MSR(写)指令操作CPSR寄存器和SPSR寄存器使用(1)
    Nand Flash驱动(实现初始化以及读操作)
    makefile使用.lds链接脚本以及 $@ ,$^, $,< 解析
    makefile初步制作,arm-linux- (gcc/ld/objcopy/objdump)详解
    Liunx-常用命令杂烩(5)
  • 原文地址:https://www.cnblogs.com/-nbloser/p/8552057.html
Copyright © 2011-2022 走看看