Python3.7实现自动刷博客访问量(只需要输入用户id)(转)

新增了代理功能,代码很浅显易懂不想多余讲解

import re
import requests
from requests import RequestException
import time
import random
from bs4 import BeautifulSoup

# 获取网页的response文件
def get_response(url):
    try:
        headers = {
            ‘Referer‘: ‘https://blog.csdn.net‘,  # 伪装成从CSDN博客搜索到的文章
            ‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36‘
            # 伪装成浏览器
        }
        # 设置代理ip
        porxy_list = [
            {"http": "http://218.60.8.99:3129"},
            {"http": "http://114.226.244.78:9999"},
            {"http": "http://39.137.95.71:80"},
            {"http": "http://115.159.31.195:8080"},
            {"http": "http://39.137.69.7:8080"},
            {"http": "http://39.106.66.178:80"},
            {"http": "http://101.4.136.34:81"},
            # 最新添加
            {"http": "http://1.197.10.199:9999"},
            {"http": "http://115.216.79.93:9999"},
            {"http": "http://123.149.136.215:999"},
            {"http": "http://39.108.92.182:8888"},
            {"http": "http://221.1.200.242:43399"},
            {"http": "http://175.42.123.88:9999"},
            {"http": "http://223.241.119.0:9999"},
            {"http": "http://59.44.78.30:54069"},
            {"http": "http://114.104.185.114:9999"},
            {"http": "http://163.204.247.84:9999"},
            {"http": "http://123.149.141.128:9999"},
            {"http": "http://223.215.6.181:9999"},
            {"http": "http://106.85.143.27:9999"},
            {"http": "http://123.163.27.131:9999"},
            {"http": "http://61.145.4.204:9999"},
            {"http": "http://183.166.162.198:9999"},
            {"http": "http://110.243.2.57:9999"},
        ]
        proxy = random.choice(porxy_list)
        response = requests.get(url, headers=headers, proxies=proxy)
        if response.status_code == requests.codes.ok:  # 响应状态码是200 或者Requests还附带了一个内置的状态码查询对象
            return response.text
        return None
    except RequestException:
        print(‘请求出错‘)
        return None

# 获取博客中所有的文章链接,在下面soup对象创建过程中,如果网页编码为其他应该,加一个from_encoding=‘UTF-8‘
def get_url(html, u_name):
    url_list = []
    num = re.findall(r‘<div.*?article-item-box csdn-tracking-statistics.*?data-articleid.*?(\d+).*?>‘, html)
    for x in range(len(num)):
        url = f‘https://blog.csdn.net/{u_name}/article/details/{num[x]}‘
        url_list.append(url)
    return url_list

# 查询博客有多少页(暂时没想到更好的方法,以后会完善的)
def get_page(u_name):
    var = 1
    while True:
        url = f‘https://blog.csdn.net/{u_name}/article/list/{var}‘
        list1 = get_url(get_response(url), u_name)
        if len(list1):
            var += 1
        else:
            break
    return var - 1

# 获取文章总阅读量
def get_all(html):
    read_num = int(re.compile(r‘<dl.*?text-center.*?title.*?(\d[0-9][0-9][0-9]*).*?>‘).search(html).group(1))
    return read_num

def parse_page(html):
    try:
        read_num = int(re.compile(‘<span.*?read-count.*?(\d+).*?</span>‘).search(html).group(1))
        return read_num
    except Exception:
        print(‘解析出错‘)
        return None

# 获取每篇文章标题
def get_name(url):
    html = get_response(url)
    soup = BeautifulSoup(html, ‘html.parser‘)
    return soup.title.string

# 入口
def main():
    url_old = []        # 用于存储用户每一页的文章链接
    url_new = []        # 用于存储用户的每一篇文章的链接
    var_all = 0         # var_all 用于存储每一轮新增的访问总量总和
    user_name = input("请输入你的CSDN用户名:")
    page_num = get_page(user_name)
    print(f‘你的博客一共有{page_num}页‘)
    # 获取所有文章列表
    for num in range(page_num):
        temp = num + 1
        url_old.append(f‘https://blog.csdn.net/{user_name}/article/list/{temp}‘)
        url_new += get_url(get_response(url_old[num]), user_name)
    art_num = len(url_new)
    print(f‘你的博客目前文章数{art_num}‘)
    var1 = get_all(get_response(url_new[0]))        # var1 用于存储刷取前的访问总量
    print(‘当前总阅读量:‘, var1)
    while True:
        for x in range(len(url_new)):
            html = get_response(url_new[x])
            read_num = parse_page(html)
            print(‘当前阅读量:‘, read_num)
            if art_num < 40:
                sleep_time = random.randint(60, 65)
            else:
                sleep_time = 1
            print(‘please wait‘, sleep_time, ‘s‘)
            time.sleep(sleep_time)  # 设置访问频率,过于频繁的访问会触发反爬虫
            print(f‘文章 {x + 1}/{art_num}:‘)
            print(get_name(url_new[x]), ‘已成功访问‘)
        var2 = get_all(get_response(url_new[0]))  # var2 用于存储刷取后的访问总量
        print(‘当前循环增加的阅读量为:‘, var2 - var1)
        var_all += (var2 - var1)
        print(f‘程序运行期间增加的总阅读量为{var_all}‘)

if __name__ == ‘__main__‘:
    main()

来自:https://blog.csdn.net/solitudi/article/details/104209520

原文地址:https://www.cnblogs.com/gisoracle/p/12283877.html

时间: 2024-08-29 07:09:09

Python3.7实现自动刷博客访问量(只需要输入用户id)(转)的相关文章

python爬虫设计刷博客访问量(刷访问量,赞,爬取图片)

需要准备的工具: 安装python软件,下载地址:https://www.python.org/ Fiddler抓包软件:http://blog.csdn.net/qq_21792169/article/details/51628123 刷博客访问量的原理是:打开一次网页博客访问量就增加一次.(新浪,搜狐等博客满足这个要求) count.py <span style="font-size:18px;">import webbrowser as web import time

Python 自动刷博客浏览量

哈哈,今天的话题有点那什么了哈.咱们应该秉承学习技术的角度来看,那么就开始今天的话题吧. 思路来源 今天很偶然的一个机会,听到别人在谈论现在的"刷量"行为,于是就激发了我的好奇心.然后看了下requests模块正好对我有用,就写了一个简单的测试用例.神奇的发现这一招竟然是管用的.那还等什么,开刷咯. 前奏 思路很简单,就是一个发送请求的实现,就可以了.代码如下: headers = { 'referer':'http://blog.csdn.net/', 'User-Agent':'M

刷流量,免费手机在线刷网站流量,刷网站PV,刷博客流量,刷博客访问量

刷流量,免费手机在线刷网站流量,刷网站PV,刷博客(淘宝)流量,刷博客(淘宝)访问量,用手机浏览器或者微信扫以下二维码: 有图有真相:还怕网站每天流量极低的站长们,还有网店的店主们,动动你们的手指,打开手机浏览器或微信扫扫二维码:你会惊讶的看到,手机也能刷网站(网店)流量,网站PV哦!    网站来源:http://www.learnphp.cn

使用python爬取csdn博客访问量

最近学习了python和爬虫,想写一个程序练练手,所以我就想到了大家都比较关心的自己的博客访问量,使用python来获取自己博客的访问量,这也是后边我将要进行的项目的一部分,后边我会对博客的访问量进行分析,以折线图和饼图等可视化的方式展示自己博客被访问的情况,使自己能更加清楚自己的哪些博客更受关注,博客专家请勿喷,因为我不是专家,我听他们说专家本身就有这个功能. 一.网址分析 进入自己的博客页面,网址为:http://blog.csdn.net/xingjiarong 网址还是非常清晰的就是cs

sublime text2自动提交博客到博客园

进入博客园,点击右上角设置 点击博客设置 在页面最下方找到你的网址 打开sublime text2,按下面步骤操作 打开之后,把你的压缩包复制进去 之后在打开箭头指向的文件 修改225行的内容,你的网址,用户名,密码 修改225行的内容,同上(你的网址,用户名,密码) 配置完成,开始写你的博客,写好之后,mac下按 fn+shift+f6之后会在头部插入以下内容(title中得内容是我自己添加的标题) 一切就绪之后,mac下按fn+command+f6自动提交到博客园 sublime text2

使用statcounter统计Hexo博客访问量

title: 使用statcounter统计Hexo博客访问量 date: 2019-05-30 20:55:29 tags: 配置 --- 介绍 statcounter是一个提供网站访问统计服务的网站: StatCounter is a simple but powerful real-time web analytics service that helps you track, analyse and understand your visitors so you can make goo

postman---postman自动发博客

前面写了一篇如何通过Cookies值去登录博客园,今天我们来通过登录博客园之后,我们进行通过Postman自动写博客 自动写博客 1.打开Postman.填写博客园对应的Cookies: 2.抓取编写博客的地址和请求参数 3.通过Postman携带Cookies请求编写博客接口 4.进行完成发送保存操作 填写Cookies 这个地方上一篇已经写过了,这里不做过多的介绍了. 具体内容详情见postman---postman通过Cookies登录博客园 抓取博客园编写博客地址 1.通过F12或者Fi

python实现的刷博客浏览量(有待改进)

python3.4, 使用了url.request,re ,bs4这些库, 在mooc看了很久爬虫的代码, 感觉自己可以实现这么一个贱贱的功能, 但是写完了之后访问页面是可以的, 但是浏览量并不增加. 宝宝心里苦, 感觉还要每次清空Cookie, 有空再改. import urllib.request import re import time import random from bs4 import BeautifulSoup p = re.compile('/MnsterLu/p/....

自动生成博客目录

操作说明 关于博客目录自动生成,已经封装成catalog.js文件,只要引用该文件即可 //默认地,为页面上所有的h3标签生成目录 <script src="http://files.cnblogs.com/files/xiaohuochai/catalog.js"></script> //或者,为页面上所有class="test"的标签生成目录 <script src="http://files.cnblogs.com/fi